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
- WordPress get_posts function, 1300 lines long
- Initiating WP_Query() with no args and adding them later through the query() method
- Pagination custom query
- WP_Query and name__in
- WP Query with offset breaks wp_pagenavi or any pagination
- Show list of authors with latest post NOT older than a month
- Interupting the loop with extra divs to display data, and how to get it to work responsively
- Custom category search box for WordPress
- Sub-loop / nested loops Best Practices
- How to echo data after a WP_Query
- WP_Query returns random number of posts
- How do I get the title of a category in a custom loop?
- Load More Posts Button – AJAX
- Is it a good idea to improve meta query performance by adding tax query?
- WP_Query: Group events by year, sorted DESC; then by date for each year group, sorted ASC
- Best practice for query_posts in responsive design?
- hide custom post types with specific meta key ON admin backend
- Orderby listing issue
- Current post in AJAX call is always zero
- why does not my wp_query work?
- How to access custom WordPress database tables
- how update data through ajax and jquery
- WP_Query arguments relation shows AND instead of OR
- Combine results of multiple WP_Query to resemble single WP_Query
- Using WP_Query() in Magento shows error
- Utilising an existing page while using the “s” query parameter
- AJAX Breaking Offset Argument In WP Query
- Pagination in html table is not working
- Why does WP_Query have methods that return public properties of the same name
- Don’t repeat posts from children in parent taxonomy query
- WP_query paged pagination with excluded category still counts it
- meta_query with array as value with multiple arrays
- Filter for each loop when WP_Query has no posts to show
- How sort products by calculate value? ( custom post meta, price, option)
- wc_get_products() return empty object
- WP_Query not returning custom post type
- How do I use $wp_query->current_post with get_template_part? I’m trying to add post classes (first/last/even/odd) to custom loops
- Why pagination is not working with tax_query param?
- From admin edit user page query either the user_nicename or username field value of the user profile being edited or viewed
- Inline Ajax call after term is appended with a @ or # etc. displayed in div
- Query custom post type by date field only working when two posts match the query
- Why isn’t my Meta_Query running?
- How to specify a certain amount of images queried, not all?
- How to show featured post first, then separate loop for other posts
- error with $query->have_posts()
- Display Featured image from custom post type category (custom taxonomy) wise