Site logo

Archived topic

Adding custom post type to loop breaks site menu?

3 replies · Started by Jeff on August 11, 2020

Viewing posts 1–4 of 4

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');

Hi there,

try including this condtion:

$query->is_main_query()

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

You're welcome

This archived topic is closed to new replies.