1

I am trying to make the category page on my Wordpress website. To position some of my content, I use post tags. To get the post that goes in a specific spot on my page, I make a WP_Query with $args for the post that has the wanted tag and is of the correct category. However, some posts go in multiple places and therefore have multiple tags. When I add a second tag to a post, the post isn't returned by either query. It seems like this is because the query is looking for posts and sees that one of the tag matches, but since the other does not match, the post is not retrieved. How do I make it so that the query gets all posts that have the requested tag, but can also have other tags? Here is my query code:

$numberOfSideBarArticles = 4;
$args = array (
    'post_type' => 'post',
    'cat' => get_query_var('cat'),
    'post__not_in' => get_option("sticky_posts"),
    'tag' => 'featured-sidebar',
    'posts_per_page' => `$numberOfSideBarArticles`
);
$the_query = new WP_Query($args);

featured-sidebar is the tag I am looking for. I want to query for all posts in the category with that tag, even if it has other tags as well. Any help or suggestions are appreciated!

0

Ignore this question, I'm not sure how or if I should delete it. My issue was that when I added multiple tags to my post, I separated them with spaces rather than commas, so it was interpreting it as one long tag which didn't match the query tags.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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