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
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
Thanks for the details, checking it in your website, will update here if there is anything found
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.
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
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
That's excellent - My issue is resolved now.
Just removed vardump line 😉
Thank you!