Created
February 7, 2022 03:39
-
-
Save wpexplorer/ac48b7b0a234140ce5dd80f4067c6671 to your computer and use it in GitHub Desktop.
Exclude Category (red) from Related Posts | Total WordPress Theme
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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