Saltar navegación

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

This support ticket is created hace 1 año, 4 meses. 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
- 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)

Este tema contiene 3 respuestas, tiene 2 mensajes.

Última actualización por Minesh hace 1 año, 4 meses.

Asistido por: Minesh.

Autor
Mensajes
#2678605

Hey! I've just found another problem.

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

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

cheers

#2678622

Minesh
Colaborador

Idiomas: Inglés (English )

Zona horaria: 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":
- enlace oculto

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
Colaborador

Idiomas: Inglés (English )

Zona horaria: 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!!