Skip Navigation

[Resolved] Get parametric search values to find text WITHIN, not EQUAL TO a custom field 2

This support ticket is created 8 years, 3 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

Tagged: 

This topic contains 2 replies, has 2 voices.

Last updated by simonF-5 8 years, 3 months ago.

Assisted by: Minesh.

Author
Posts
#358015

FAO: Minesh (https://toolset.com/forums/users/minesh/)

Hi Minesh,
Thank you for your help with the parametric search. Your solution works for the 'Recommended Use' values, but not for the 'Difficulty' ones. I tried to copy the same filter substituting wpcf-difficulty for wpcf-use, but all I got was a 500 Internal Server Error on page reload. How do I go about making it work there?

#358021

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

I've changed the code so your difficulty field also get counted with your search. Please find following modified code and I hope this will resolve your issue. I've already added this code to your functions.php file.

add_filter( 'wpv_filter_query', 'custom_search_criteria',10,2 );
function custom_search_criteria( $query_args ,$view_settings ) {
if (isset($view_settings['view_id']) && $view_settings['view_id'] == 1283 ) {
	
	foreach((array)$query_args['meta_query'] as $k=>$v):
            if(isset($v['key']) and ($v['key']=='wpcf-use' or $v['key']=='wpcf-difficulty')){
						
				$values = explode(",",$v['value']);
				if(count($values) > 1){
					$key = $v['key'];
					unset($query_args['meta_query'][$k]);
					
					foreach($values as $x=>$y):
						//$query_args['meta_query'][$k][$x]['key'] = 'wpcf-use';
						$query_args['meta_query'][$k][$x]['key'] = $key;
						$query_args['meta_query'][$k][$x]['type'] = 'CHAR';
						$query_args['meta_query'][$k][$x]['compare'] = 'LIKE';
						$query_args['meta_query'][$k][$x]['value'] = $y;
					endforeach;
					$query_args['meta_query'][$k]['relation'] = 'OR';
				}
			}
        endforeach;
}
return $query_args;
}
#358143

Thank you again Minesh, this works fantastically!
Best,
Simon

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.