I have the following working code for a query on a specific category and tag slug:
$args = array(
'category_name' => $cat_name,
'tag' => $tag_name,
'post__not_in' => $sticky
);
$my_query = new WP_Query( $args );
I can’t figure out how to exclude a specific tag name from the query. Do I need the tag ID? How do I get it? Thank you in advance.
2 Answers
Use tag__not_in
parameter. You have to use tag ID for this parameter
$args = array(
'category_name' => $cat_name,
'tag' => $tag_name,
'post__not_in' => $sticky,
'tag__not_in' => array($tag_id_1, $tag_id_2)
);
$my_query = new WP_Query( $args );