[Resolved] Adding custom post type to category hides nav

Home Forums Support [Resolved] Adding custom post type to category hides nav

Home Forums Support Adding custom post type to category hides nav

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

    When I add this code to my child theme functions.php (to include a custom post type), the navigation menu disappears from my category pages. Trying to figure out why.

    add_filter('pre_get_posts', 'query_post_type');
    function query_post_type($query) {
    	if(is_category() || is_tag()) {
    		$post_type = get_query_var('post_type');
    	if($post_type)
    			$post_type = $post_type;
    	else
    			$post_type = array('post','ebook');
    		$query->set('post_type',$post_type);
    	return $query;
    		}
    }
    #775806
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Try adding this to the top of your function:

    if ( ! $query->is_main_query() ) {
        return;
    }

    Let me know ๐Ÿ™‚

    #776697
    Adam

    That did it, thanks.

    #776741
    Tom
    Lead Developer
    Lead Developer

    You’re welcome ๐Ÿ™‚

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