I have a section that want to include featured posts. I want to look for featured posts based on tag. For example, I want to fetch all the latest posts that have the featured tag.

I use the following query to do that

$featPosts = new WP_Query(array(
    'posts_per_page' => 5,
    'tag_slug__in' => 'featured', //The tag-slug
        'post_status' => 'publish',
        'order_by' => 'date',
        'order' => 'DESC',
        'ignore_sticky_posts' => 1

The issue here is that some random posts appear that don't have the featured tag.

Any idea why this might be happening? Any help appreciated :)


tag_slug__in should be an array, not a string, that is why your query fails

'tag_slug__in' => ['featured'], // Requires PHP 5.4+, use array( 'featured' ) pre 5.4

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.