WordPress Selected posts on home page based on tags

Tag Parameters

We can show posts based on only selected tags from wordpress tags. For this we can use “query_posts” function. Just Goto Appearance –>  Editor –> select page Index.php and place the below code and see.

Show posts associated with certain tags.

  • tag
  • tag__and
  • tag__in
  • tag_slug__and
  • tag_slug__in

Fetch posts for one tag


Fetch posts that have either of these tags


Fetch posts that have all three of these tags:


Multiple Tag Handling

Display posts that are in multiple tags:

query_posts(array('tag__and' => array('bread','baking'));

This only shows posts that are in both tags ‘bread’ and ‘baking’. To display posts from either tag, you could use tag as mentioned above, or explicitly specify by using tag__in:

query_posts(array('tag__in' => array('bread','baking'));

The tag_slug__in and tag_slug__and behave much the same, except match against the tag’s slug instead of the tag itself.

Hope this helps. If required anything please post a comment.