Support » Plugins » posts_where filter altering wp_nav_menu

  • I’ve been try to figure out a way to order my custom post type by two different custom meta values. I finally got this all working, and then found out that it messed up my navigation. Suddenly my main navigation can’t find my menu, so it prints out all pages instead. This is the only page that uses special filters and the only page where the menu is not displaying correctly.

    <?php wp_nav_menu( array('menu' => 'main-menu' )); ?>

    I use the following filters, but the where seems to be the problem. If I remove it, all is fine:
    – posts_join
    – posts_where
    – posts_groupby
    – posts_orderby

    add_filter('posts_where', 'edit_posts_where');
    function edit_posts_where($where_statement) {
        global $wpdb;
    	if( is_post_type_archive('episodes') && !is_admin() && is_main_query() ) {
    		$where_statement .= " AND ({$wpdb->postmeta}.meta_key = 'season_number' AND (mt1.meta_key = 'season_number' AND CAST(mt1.meta_value AS CHAR) LIKE '%%') AND (mt2.meta_key = 'episode_number' AND CAST(mt2.meta_value AS CHAR) LIKE '%%') )";
    	return $where_statement;

    Has anyone ever used these filters and have an idea why it can’t find my menu when the posts_where filter is enabled?
    Thank you!

  • The topic ‘posts_where filter altering wp_nav_menu’ is closed to new replies.