1

On my tag.php page, I want to show posts with multiple tags...

I have something like this:

mypage.com/tag/tag1+tag2+tag3/

$tags = get_queried_object()->slug; //returns only 'tag1' !!

$args = array( 
    'tag' => $tags //need to get 'tag1+tag2+tag3' here
);

$loop = new WP_Query($args);

Is there any other way how to show posts with multiple tags?

1 Answer 1

0

get_query_var( 'tag' ) will return you 'tag1+tag2+tag3' string.

get_query_var( 'tag_slug__and' ) will return you the array of tags.

So, there are two ways to achieve the goal:

$args = array( 
    'tag' => get_query_var( 'tag' ), // string
);

or

$args = array( 
    'tag__and' => get_query_var( 'tag_slug__and' ), // array
);

It remains to be seen how do you plan to create tag1+tag2+tag3 slug.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.