Hey! I've just found another problem.
If I use your wpml-string shortcode solution, the search filter doens't work properly.
On versteckter Link you can see the pager displays 11 pages (image search1.png).
If you click on Official Discovery Points checkbox, the result pager displays 14 pages and there isn't any paramenter in the URL (image search2.png).
Instead, if you test the search on this page versteckter Link , you will see it works fine and the URL displays the wpv-wpcf-official-discovery-point=1 parameter (image search3.png).
This page uses a view (versteckter Link ) where I removed the wpml-string shortcode because it seems that it doesn't work with white spaces in the label.
cheers
Minesh
Unterstützer
Sprachen:
Englisch (English )
Zeitzone:
Asia/Kolkata (GMT+05:30)
Hello. Thank you for contacting the Toolset support.
I've added the following filter to the "Custom code" section offered by Toolset with the code snippet "custom1":
- versteckter Link
function func_archive_filter_discovery_point($query) {
$term = $query->get_queried_object();
if ( $query->is_tax('discover') and defined('DOING_AJAX') && DOING_AJAX) {
foreach((array)$_POST['search']['dps_general'] as $k=>$v):
if($v['name']=="wpv-wpcf-official-discovery-point" and $v['value']==1){
$current_filter_value = $v['value'];
$meta_args_query[] = array(
'key'=>'wpcf-official-discovery-point',
'value'=>$current_filter_value,
'type'=>'NUMERIC',
'compare'=>'=',
);
}
endforeach;
$query->query_vars['meta_query'] = $meta_args_query;
}
}
add_action('pre_get_posts', 'func_archive_filter_discovery_point',999);
Can you please confirm it works as expected now.
Hi Minesh, it works great. How can I make it work for other taxonomies or all the taxonomies?
thanks
Minesh
Unterstützer
Sprachen:
Englisch (English )
Zeitzone:
Asia/Kolkata (GMT+05:30)
You can modify the code to check for your multiple taxonomies with is_tax() function.
For example:
function func_archive_filter_discovery_point($query) {
$taxonomies_to_check = array('discover', 'tax-1','tax2');
$term = $query->get_queried_object();
if ( $query->is_tax($taxonomies_to_check) and defined('DOING_AJAX') && DOING_AJAX) {
foreach((array)$_POST['search']['dps_general'] as $k=>$v):
if($v['name']=="wpv-wpcf-official-discovery-point" and $v['value']==1){
$current_filter_value = $v['value'];
$meta_args_query[] = array(
'key'=>'wpcf-official-discovery-point',
'value'=>$current_filter_value,
'type'=>'NUMERIC',
'compare'=>'=',
);
}
endforeach;
$query->query_vars['meta_query'] = $meta_args_query;
}
}
add_action('pre_get_posts', 'func_archive_filter_discovery_point',999);
Where:
- Replace values for variable $taxonomies_to_check for 'tax-1' and 'tax-2' with your desired taxonomy slug.
More info:
- https://developer.wordpress.org/reference/functions/is_tax/