Skip Navigation

[Resolved] Split: Custom search problem with checkbox label translation – filter not working for taxonomy

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
- 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)

This topic contains 3 replies, has 2 voices.

Last updated by Minesh 11 months, 1 week ago.

Assisted by: Minesh.

Author
Posts
#2678605

Hey! I've just found another problem.

If I use your wpml-string shortcode solution, the search filter doens't work properly.

On hidden 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 hidden 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 (hidden link) where I removed the wpml-string shortcode because it seems that it doesn't work with white spaces in the label.

cheers

#2678622

Minesh
Supporter

Languages: English (English )

Timezone: 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":
- hidden 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.

#2678937

Hi Minesh, it works great. How can I make it work for other taxonomies or all the taxonomies?

thanks

#2679053

Minesh
Supporter

Languages: English (English )

Timezone: 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/

#2679115

Thanks!!