Skip Navigation

[Resolved] Old solution no longer works

This support ticket is created 4 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.

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/Hong_Kong (GMT+08:00)

This topic contains 6 replies, has 2 voices.

Last updated by Chris 4 years, 3 months ago.

Assisted by: Luo Yang.

Author
Posts
#1458059

In the thread https://toolset.com/forums/topic/filtering-using-manually-entered-values/ you kindly helped me some achive some custom search criteria using wpv_filter_query.
Nothing has changed about my requirements or the fields involved but It would seem that the code as added to my functions.php file from that thread no longer works. Maybe some recent views updates have changed things...
Are there any changes to that code that would fix this?
Many thanks

#1459165

Hello,

Since it is a custom PHP codes problem, please provide a test site with the same problem, also point out the problem page URL and view's URL, where I can edit your PHP codes, I need a live website to test and debug, thanks

#1461383

Thanks for the details, checking it in your website, will update here if there is anything found

#1461387

There are two PHP error/notice in problem URL:
1) Notice: Undefined index: meta_query in /home/doulaor1/dev.doula.org.uk/wp-content/themes/doulauk/functions.php on line 859

It can be fixed by adding below codes in line 858~860:

if(!isset($query_args['meta_query'])){
    $query_args['meta_query'] = array();
}

2) Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 2101248 bytes) in
Please try to increase your website PHP memory limitation, and test again, see WordPress document:
https://wordpress.org/support/article/editing-wp-config-php/#increasing-memory-allocated-to-php

Since the FTP access you provided is not valid, I can not modify the wp-config.php in your website, you will need to change it yourself.

#1461607

Thank you for the update.

The php error is now gone and I have increased php memory to 256M

However, the results are still not displaying as I need them to.

As copied from the old thread:
1 => it should return records with 1 and 3
2 => it should return records with 2 and 3
3 => it should return records with 3 only

Many thanks

#1461831

I have changed the PHP codes as below:


add_filter( 'wpv_filter_query', 'custom_search_criteria',999,2 );

function custom_search_criteria( $query_args ,$view_settings ) {

if (isset($view_settings['view_id']) && $view_settings['view_id'] == 19586 ) {
	if(!isset($query_args['meta_query'])){
		$query_args['meta_query'] = array();
	}
		foreach((array)$query_args['meta_query'] as $k=>$v):
			if(isset($v['key']) and $v['key']=='wpcf-type-of-doula-service-offered'){
				if(!isset($v['value'][0])){
					continue;
				}
				if($v['value'][0]==1){
					$query_args['meta_query'][$k]['compare']= 'IN';
					$query_args['meta_query'][$k]['value']= array(1,3);
				}else if($v['value'][0]==2){
					$query_args['meta_query'][$k]['compare']= 'IN';
					$query_args['meta_query'][$k]['value']= array(2,3);
				}
				var_dump($query_args['meta_query'][$k]);
			}
		endforeach;

}
return $query_args;

}

Please test again, check if it is fixed, thanks

#1462217

That's excellent - My issue is resolved now.
Just removed vardump line 😉

Thank you!

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