Exclude custom post type category from homepage

Hi all,

I am using a Strict Themes, Theme Forset 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 a category called ‘wastelands’ which is 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…

Very best,
Hannah

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

?>

Hey there, and welcome to the community forums! To get an answer to technical questions regarding items it’s best to contact the author of that item. Please visit the item’s page and write your support question in the item comments. Cheers! :slight_smile: