I have a post type which contains television programs. Each post has title and time of showing.
What I would like to do is to have a list of times of showing. So I set up a view with Post search filter query
filter post title by a search term set by the View shortcode attribute: search. eg. [wpv-view name="view-name" search="search term"]
On the content template for the post type I include:
[wpv-view name="other-showings" search='[wpv-post-title]']
This works fine unless the Post Title of the posts contain a special character like - or '. Then nothing is returned from the view.
Can this be fixed somehow? Do you offer an example of custom code which I could add to make it work?
Hi Bob,
Thank you for contacting us.
Since Nigel is away on vacations until next week, I'll be helping you with this ticket.
This limitation of using search for titles with special characters has already been reported to the concerned team:
https://toolset.com/errata/views-cannot-query-posts-whose-titles-contain-apostrophe/
I'm afraid, I don't have a time estimate to share at the moment for a possible fix, but I'll keep you updated with the progress through this ticket.
For now, you can use a workaround of replacing such special characters with their HTML Entity code ( ref: hidden link ) using the "wpv_filter_query" filter, as explained in this reply:
https://toolset.com/forums/topic/searches-with-apostrophe-return-no-results-using-content-search-in-query-filter-2/#post-1128106
I hope this helps and please let me know if you need any further assistance around this.
regards,
Waqar
Thanks. That solves the ' issue. Could you give an example of how to add additional replacing of special chars to the existing code provided in your link so it can handle both say ' and - ?
Or can I simply add multiple replace functions to the same view id?
Hi Bob,
Thanks for the update and glad that it works.
For additional special characters, you can extend the function like this:
function tssupp_filter_query($view_args, $view_settings, $view_id) {
if (in_array($view_id, array(496))) {
if (isset($view_args['s'])) {
$view_args['s'] = str_replace("–", "-", $view_args['s']);
$view_args['s'] = str_replace("‘", "'", $view_args['s']);
$view_args['s'] = str_replace("’", "'", $view_args['s']);
}
}
return $view_args;
}
add_filter('wpv_filter_query', 'tssupp_filter_query', 101, 3);
regards,
Waqar
My issue is resolved now. Thank you!
Hi Bob,
I'd like to update that a fix for the special characters issue, has been included in the latest Blocks/Views releases.
You're welcome to update to the most recent Toolset plugins versions and let us know in case the issue still persists, through a new ticket.
regards,
Waqar