I have a code snippet installed on the Custom Code section of Toolset Settings that excludes child categories from a search filter. You can see the search here: hidden link
I have it set to run always and everywhere, including on Ajax calls. However, when I use ajax pagination or ajax to clear search filters, the code doesn't run. However, when I use ajax to search, the code still works. The code follows:
<?php
/**
* New custom code snippet (replace this with snippet description).
*/
toolset_snippet_security_check() or die( 'Direct access is not allowed' );
add_shortcode('limit_categories', 'limit_categories_func');
function limit_categories_func($atts){
extract( shortcode_atts( array(
'categories' => '',
), $atts ) );
$categories_arr = explode(',', $categories);
return implode(',', array_slice($categories_arr, 0, 1));
}
function func_display_only_parent_terms( $query ){
global $post;
if ( $post->ID == 944 && $query->query_vars['taxonomy'][0] == 'category' && !is_admin() ) {
$query->query_vars['parent'] = 0;
}
if
( $post->ID == 18 && $query->query_vars['taxonomy'][0] == 'category' && !is_admin() ) {
$query->query_vars['parent'] = 0;
}
}
add_action( 'pre_get_terms', 'func_display_only_parent_terms',10,1);