Skip to main content
adding information
Source Link

EDIT: Just noticed this seems to work on every page but the frontpage to exclude the nav menu $query->query_vars['post_type'] != 'nav_menu_item' Would there be any reason that the function has access to the query_vars being passed to WP_Query on every page except the front page? Only frontpage is throwing this error:

<b>Notice</b>:  Undefined property: WP_Query::$post in <b>...wp-includes/query.php</b> on line <b>3034</b><br />
<br />
<b>Notice</b>:  Trying to get property of non-object in <b>...wp-includes/query.php</b> on line <b>3402</b><br />
<br />
<b>Notice</b>:  Trying to get property of non-object in <b>...wp-includes/query.php</b> on line <b>3404</b><br />
<br />
<b>Notice</b>:  Trying to get property of non-object in <b>...wp-includes/query.php</b> on line <b>3406</b><br />
<br />
<b>Notice</b>:  Undefined property: WP_Query::$post in <b>...wp-includes/query.php</b> on line <b>3034</b><br />
<br />
<b>Notice</b>:  Trying to get property of non-object in <b>...wp-includes/query.php</b> on line <b>3402</b><br />
<br />
<b>Notice</b>:  Trying to get property of non-object in <b>...wp-includes/query.php</b> on line <b>3404</b><br />
<br />
<b>Notice</b>:  Trying to get property of non-object in <b>...wp-includes/query.php</b> on line <b>3406</b><br />
<br />
<b>Notice</b>:  Undefined index: post_type in <b>...lib/custom.php</b> on line <b>1051</b>

and lastly,...sadly,...is_main_query() just won't work. (we found ourselves in some sticky situations that required some secondary queries.)

and lastly,...sadly,...is_main_query() just won't work. (we found ourselves in some sticky situations that required some secondary queries.)

EDIT: Just noticed this seems to work on every page but the frontpage to exclude the nav menu $query->query_vars['post_type'] != 'nav_menu_item' Would there be any reason that the function has access to the query_vars being passed to WP_Query on every page except the front page? Only frontpage is throwing this error:

<b>Notice</b>:  Undefined property: WP_Query::$post in <b>...wp-includes/query.php</b> on line <b>3034</b><br />
<br />
<b>Notice</b>:  Trying to get property of non-object in <b>...wp-includes/query.php</b> on line <b>3402</b><br />
<br />
<b>Notice</b>:  Trying to get property of non-object in <b>...wp-includes/query.php</b> on line <b>3404</b><br />
<br />
<b>Notice</b>:  Trying to get property of non-object in <b>...wp-includes/query.php</b> on line <b>3406</b><br />
<br />
<b>Notice</b>:  Undefined property: WP_Query::$post in <b>...wp-includes/query.php</b> on line <b>3034</b><br />
<br />
<b>Notice</b>:  Trying to get property of non-object in <b>...wp-includes/query.php</b> on line <b>3402</b><br />
<br />
<b>Notice</b>:  Trying to get property of non-object in <b>...wp-includes/query.php</b> on line <b>3404</b><br />
<br />
<b>Notice</b>:  Trying to get property of non-object in <b>...wp-includes/query.php</b> on line <b>3406</b><br />
<br />
<b>Notice</b>:  Undefined index: post_type in <b>...lib/custom.php</b> on line <b>1051</b>

and lastly,...sadly,...is_main_query() just won't work. (we found ourselves in some sticky situations that required some secondary queries.)

Source Link

Looking for a way to exclude frontpage and nav menu from query filter

maybe I'm thinking about this the wrong way, but I need to: A) exclude posts in queries site-wide (minus frontpage and navbar) based on a comparison with a meta_value, and B) orderby a differnt meta_value_num, then title

this works:

function my_get_posts( $query ) {
    $today = current_time( 'timestamp', 0 );
    if ( ! is_admin() && ! is_home() && ! $query->is_page('Locations')) {
        $query->set( 'meta_key', 'wpcf-post-weight' );
        $query->set( 'orderby', 'meta_value_num title' );
        $query->set( 'order', 'ASC' );

        $meta_query = array(
            array(
                'key' => 'wpcf-news-expire-date',
                'value' => $today,
                'compare' => '>='
            )
        );

        $query->set( 'meta_query', $meta_query );
    }

    return $query;
}
add_filter( 'pre_get_posts', 'my_get_posts' );

But, since pre_get_posts can not use is_front_page() as a conditional, I'm a little stuck about how to exclude the front page. Would changing the hook to parse_query, then using is_front_page() be the way to go?

Also, I notice that the pages this function gets called on no longer have the nav menu generated by Appearance>Menus. I can only assume this is because the menu is generated with a query. I have no idea how to exclude the nav query in particular.

and lastly,...sadly,...is_main_query() just won't work. (we found ourselves in some sticky situations that required some secondary queries.)

Any help or thoughts would be greatly appreciated. Thank you.