[Resolved] Adding custom post type to loop breaks site menu?

Home Forums Support [Resolved] Adding custom post type to loop breaks site menu?

Home Forums Support Adding custom post type to loop breaks site menu?

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

    I have a custom post type called Reviews, and I have some code in a plugin to make it so that it displays in archives and the loop, etc.

    For some reason, if the lines of code below are active in my plugin, the menu at the top of my page disappears. I’m fairly sure this wasn’t always the case.

    function add_post_types_to_loop_and_feed($query) {
    
        if ( is_home() || is_feed() || ( is_archive() && !is_admin() ) ) {
            $query->set('post_type', array('post', 'reviews'));
    
        }    
    }
    
    add_action('pre_get_posts', 'add_post_types_to_loop_and_feed');
    #1397068
    David
    Staff
    Customer Support

    Hi there,

    try including this condtion:

    $query->is_main_query()

    #1397526
    Jeff

    Ahh, yep, that did the trick. Thank you!

    #1397659
    David
    Staff
    Customer Support

    You’re welcome

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.