Exclude custom post type category from homepage
-
Hi all,
I am using a theme called Recital.
It uses the following custom post_type, category and taxonomy to define a portfolio homepage layout:
post_type=”st_project”
category=”st_category”
tag=”st_tag”The URL is something like this:
/wp-admin/term.php?taxonomy=st_category&tag_ID=115&post_type=st_project…I am trying to exclude ‘wastelands’ / the tag_ID ‘115’ from showing on the homepage. I have been trying the following code added to the functions.php but it is not working.
Please help…
[ Moderator note: code fixed. Please wrap code in the backtick character or use the code button. ]
<?php function exclude_cat( $query ) { if ( $query->is_home() && $query->is_main_query() ) { if ( is_post_type( 'st_project' ) ) { $tax_query = $query->get( 'tax_query' ) ?: array(); $tax_query[] = array( 'taxonomy' => 'st_category', 'field' => 'slug', 'terms' => 'wastelands', 'operator' => 'NOT IN', ); $query->set( 'tax_query', $tax_query ); } } return $query; } add_action('pre_get_posts','exclude_cat'); ?>
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Exclude custom post type category from homepage’ is closed to new replies.