Pre_get_posts filter causes menu items to disappear
-
Hi,
I have created a filter to filter posts, on the archive page in this case. I’m using pre_get_posts and the results are fine. There’s only one problem: if a filter is used, the menu doesn’t load anymore. It’s very strange and I don’t know where to look anymore.
This is the filter:
add_action('pre_get_posts', 'wmw_custom_field_filter'); function wmw_custom_field_filter($query) { $tax_query = array('relation' => 'OR'); $cat_set = false; if (isset($_GET['cat1'])) { $tax_query[] = array( 'taxonomy' => 'category', 'terms' => $_GET['cat1'], 'field' => 'term_id', ); $cat_set = true; } if (isset($_GET['cat2'])) { $tax_query[] = array( 'taxonomy' => 'category', 'terms' => $_GET['cat2'], 'field' => 'term_id', ); $cat_set = true; } if (isset($_GET['cat3'])) { $tax_query[] = array( 'taxonomy' => 'category', 'terms' => $_GET['cat3'], 'field' => 'term_id', ); $cat_set = true; } if (isset($_GET['cat4'])) { $tax_query[] = array( 'taxonomy' => 'category', 'terms' => $_GET['cat4'], 'field' => 'term_id', ); $cat_set = true; } if ($cat_set) $query->set('tax_query', $tax_query); if (isset($_GET['value'])) { $meta_query = array( array( 'key' => '_wmw_mbe_age', 'value' => $_GET['value'], 'compare' => LIKE, ), ); $query->set('meta_query', $meta_query); } return $query; }
Also when I add parameters to the url manually, the results are okay, but again the menu-items are gone. In fact the whole div with the menu items are gone (.menu-top-menu-container). So it looks like the query stops something else from being executed.
Hope someone knows what’s going wrong.
Thanks!
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Pre_get_posts filter causes menu items to disappear’ is closed to new replies.