Displaying Posts from Custom Post Types

You’re setting arguments for the main query in your pre_get_posts action, and then overwriting that query in the template by calling query_posts (which you should never use). If you want to exclude categories, do that in the same pre_get_posts action: add_action( ‘pre_get_posts’, ‘add_my_post_types_to_query’ ); function add_my_post_types_to_query( $query ) { if ( is_home() && $query->is_main_query() ){ … Read more

I am trying to hide a custom post type category to logged in users with Pre_Get_Posts

OK, so you have few mistakes in there. field can be term_id or slug, but not id. tax_query should be array of arrays and not an array. So here is fixed code: function exclude_category( $query ) { if ( is_user_logged_in() && $query->is_main_query() ) { $taxquery = array( array( ‘taxonomy’ => ‘project-type’, ‘field’ => ‘term_id’, ‘terms’ … Read more