If you read the Codex entry, you must pass an array as tag_slug__in
. In this case though, I would use tag__in
with IDs rather than slugs:
$tag_ids = array();
foreach( get_the_tags($post->ID) as $tag ) {
$tag_ids[] = $tag->term_id;
}
$recent_posts = new WP_Query(
array(
'tag__in' => $tag_ids,
'posts_per_page' => 2,
'cat' => 20
)
);
Related Posts:
- Posts with at least 3 tags of a list of tags
- Better way to get tag stats?
- Given a WP_Query, how can I get a list of tags?
- Executing Queries in tag.php
- How to order posts tag by tag?
- post_type is ignored by WP_Query when ‘tag’ argument is included
- WP Rest API v2 return posts with specific tag
- Loop through all tags & output posts in alphabetical list
- Order posts by tags count?
- How to get any tag ID
- Get all posts without tags
- WP Query for Posts (Products) in Specific Category that has 2 Specific Tags (*AND* both tags not *OR*)
- How to exclude products by tag from woocommerce shop page?
- Pagination problem after WP_Query with tag filtering
- Query post from all category with same tag on 1 pages
- reducing the amount of wp_query calls
- WordPress Related Post by tags in Single.php
- How to build a WP_Query using mulitple tags and using AND or OR operator between them
- Include tags in WP_Query
- Search for multiple tags?
- Display posts from only one post form in custom query and exclude in main query
- How can I make WP_Query get posts that have a tag but also have random other tags?
- Cluster WooCommerce products in each Category Archive by Tags assigned to products
- Display tags with random thumbnail from selection of posts with that tag
- Query posts intersecting tags and categories
- Combining categories (Query posts with multiple taxonomy terms)
- Order by most used tag
- How to not display tags with less than X posts
- Query Posts by Tag and exclude
- Get posts that do not have the same tags as current
- exclude product with available tag
- WP_Query by keyword OR post tag
- Display posts by tag
- Creating attachments archive in tags and categories
- Get posts with no tags?
- Filter products on category AND tag
- Only show tag with the same id as the post
- Get posts that match defined arrays of tags
- Order posts by tags count?
- Fix wp_term_relationships slow query in get_posts
- getting posts by tags
- Search with WP_Query, but ignore href URLs in anchor tags?
- Show posts from categories instead of tags
- post_type not working when tag__in is present?
- Related Post by Tags Code
- Exclude all tagged posts from WP_Query loop
- I cannot get tax_query in get_posts() to work with custom taxonomy
- WordPress custom query by archive title
- How to create page that lists tags by initial letter?
- Random posts in WP_Query when searching by tag
- Issue attempting a wp_query_posts with tags
- Limit Tags display and ad Drop Down Menu
- Can’t seem to get an else statement correct? [closed]
- Get posts that were most recently tagged
- How do I show related posts from categories instead of tags?
- When should you use WP_Query vs query_posts() vs get_posts()?
- When to use WP_query(), query_posts() and pre_get_posts
- WP_Query by just the id?
- Meta_query compare operator explanation
- WP_Query with “post_title LIKE ‘something%'”?
- wp query to get child pages of current page
- How to get an array of post data from wp_query result?
- How to get post id of static front page?
- meta_query with meta values as serialize arrays
- How to only display posts whose meta_value field is not empty?
- Get post ids from WP_Query?
- Pagination when using wp_query?
- Exclude post ID from wp_query
- How to print the excuted sql right after its execution
- How to extend WP_Query to include custom table in query?
- How to store and receive variables in WP sessions?
- Should I use Pre Get Posts or WP_Query
- How can i retrieve default post per page value? from settings->reading. And total number of posts?
- Nested meta_query with multiple relation keys
- Is it necessary to use wp_reset_query() in a WP_Query call?
- Can I force WP_Query to return no results?
- Can wp_query return posts meta in a single request?
- Using pre_get_posts with WP_Query
- Find out total number of pages in global query on archive page?
- WP_Query + random
- Resetting post data to previous loop in nested loops
- order by numeric value for meta value
- numberposts? showposts? posts_per_page?
- $GLOBALS[‘wp_the_query’] vs global $wp_query
- Broken? WP_Query and “attachment” as a post type
- Some doubts about how the main query and the custom query works in this custom theme?
- Order by multiple meta key and meta value [closed]
- Post_count only shows the number of results per page
- Page template query with WP_Query
- meta_query ‘compare’ => ‘IN’ not working
- Query posts only with featured image
- Wp get all the sub pages of the parent using wp query
- What is appropriate flow for custom data from URL in WP_Query?
- How to display page content in a page template?
- Ignoring initial articles (like ‘a’, ‘an’ or ‘the’) when sorting queries?
- How to merge two queries together
- Get post count of current loop when using multiple queries on one page
- why ignore_sticky_posts in sticky post query
- Wp_redirect and sending variables
- Multiple relationship for multiple tax_query in WP_Query