is_main_query returning false when trying to show must one category on home…

Community Forums Forums Design Tips and Tricks is_main_query returning false when trying to show must one category on home…

This topic is: not resolved

This topic contains 3 replies, has 2 voices, and was last updated by  Jared Williams 1 year, 9 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #29022

    dwood
    Participant
    Post count: 1

    Hi folks,

    Based on various tips found on the web, I added this code at the end ofMetro’s functions.php (Genesis 1.9.1) to try to show only one category on my home page…
    add_action( ‘pre_get_posts’, ‘only_show_algemeen_on_home’ );

    function only_show_algemeen_on_home( $query ) {

    if ( $query->is_main_query() && $query->is_home() ) {
    $query->set( ‘cat’, ‘1’ );
    }

    }

    But it looks like is_main_query() is returning false here, as the list of posts is NOT limited to cat 1 unless I remove that half of the if().  And if I simply remove is_main_query, that breaks other stuff, like whether menus are shown, so that’s not a solution either…

    Any clue what I’m doing wrong here…?

    Thanks,

    David

     

     

    #29682

    Jared Williams
    Participant
    Post count: 47

    Can you provide a link to your site?

    Metro uses the Featured Posts widget for all of the sections so adjusting the main query wouldn’t work. If you want to only show 1 category you can choose which category from within the widget.

    Or, are you just showing posts?


    #29688

    dwood
    Participant
    Post count: 1

    Hi Jared,

    Many thanks for responding…

    Sadly enough, can’t show you the site at the moment as it’s planned to go live Sunday evening late and I don’t have a proper test env…  :-(

    But to answer your second question, I’m indeed just trying to show a list of recent posts from cat=1, so not making any use of the Featured Post widget yet.

    Cheers,

    David

     

    #29934

    Jared Williams
    Participant
    Post count: 47
Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.