I'm using a custom search filter (using my custom query var type
), like so:
function fteh_pre_get_posts( $query ){
if( isset( $query->query_vars['type'] ) )
$types = explode( ',', $query->query_vars['type'] );
$query->set( 'post_type', $types );
return $query;
}
if ( ! is_admin() ) {
add_action( 'pre_get_posts', 'fteh_pre_get_posts' );
}
I noticed this causes a registered custom menu to disappear.
Without the !is_admin()
it also confused the menu builder (it showed some posts instead of all my pages in Pages section). Adding the condition helped with that, but I can't figure out how to bring back my menu.
It's properly registered and called, build and saved in proper theme location and worked before adding that filter. Now it just uses the fallback_cb
(in my case the default wp_page_menu
) instead of my custom menu.
As soon as I remove that action from pre_get_posts
, everyting is back to normal.
I don't see how pre_get_posts
hook is related to the custom menus - does anyone know why it would cause such a weird behavior?
UPDATE:
I now discovered another problem caused specifically by the snippet above - all my custom queries on pages (simple stuff like query_posts('post_type=organization')
) stopped working and display normal posts instead of custom post types set up in query_posts
.
pre_get_posts
hook is related to the custom menus" - that's because nav menu items are posts, and are queried as posts. Also: don't ever usequery_posts()
. UseWP_Query()
instead for custom query loops, or usepre_get_posts
to modify the main query.