Skip Navigation

[Resolved] View with Post search filter query – including posts with special characters

This support ticket is created 5 years, 5 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 5 replies, has 2 voices.

Last updated by Waqar 4 years, 2 months ago.

Assisted by: Waqar.

Author
Posts
#1281769

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?

#1282679

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

#1283549

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?

#1284123

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

#1284173

My issue is resolved now. Thank you!

#1792525

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