Skip to content

Instantly share code, notes, and snippets.

@wpexplorer
Created February 7, 2022 03:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wpexplorer/ac48b7b0a234140ce5dd80f4067c6671 to your computer and use it in GitHub Desktop.
Save wpexplorer/ac48b7b0a234140ce5dd80f4067c6671 to your computer and use it in GitHub Desktop.
Exclude Category (red) from Related Posts | Total WordPress Theme
// Exclude "red" term from related blog posts.
add_filter( 'wpex_blog_post_related_query_args', function( $args ) {
$exclude_terms = array(
'relation' => 'AND',
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => array( 'red' ),
'operator' => 'NOT IN',
),
);
if ( isset( $args['tax_query'] ) ) {
$args['tax_query'] = array_merge( $args['tax_query'], $exclude_terms );
} else {
$args['tax_query'] = $exclude_terms;
}
return $args;
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment