You’ll have to get the terms of current post with get_the_terms
function and then use them in your query.
// this will get terms and then get only term_ids from them
$term_ids = wp_list_pluck( get_the_terms( get_the_ID(), 'coupon_category' ), 'term_id' );
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$related = new WP_Query( array(
'post_type' => APP_POST_TYPE,
'post_status' => 'publish',
'posts_per_page' => 4,
'tax_query' => array(
array(
'taxonomy' => 'coupon_category',
'field' => 'term_id',
'terms' => $term_ids,
),
)
) );
So we use get_the_terms
to get list of terms for current post and then we call wp_list_pluck
, which is a very handy function, that will get array containing only one field from all of given objects.
PS. I’ve also changed your query_posts
to WP_Query
– it’s better for your efficiency.
Related Posts:
- How to show only one post for each categories of taxonomy of custom post that contains a specific custom field
- Counting number of posts with Category B in Category A
- Query with custom taxonomy not working
- Five posts from a category in footer
- Filtering out child category posts from parent category archive not working
- How to display an other custom post type in a different custom post type’s archive?
- Display custom tags on pages that have a specific page parent
- Filter Custom Taxonomy Posts
- How to get posts by category and by choosing a taxonomy term?
- get_the_terms has strange result since version 6.0
- Filter products on category AND tag
- query hook parse_tax_query function takes no effect
- How do I stop the same post showing multiple times in a archive?
- Related categories order posts by category
- My entry results are not consistently alphabetized
- Pull posts from all categories if quantity is not met?
- Display post list within category list sorted by name [duplicate]
- Adding a language rule and displaying posts with a custom taxonomy term on its archive page
- Display All Top Child Categories / Taxonomy
- Query post by Category and custom file (ACF)
- Show one post of each custom taxonomy
- Query WP Posts, then list the taxonomies from those posts
- trying to change from query_post to WP_Query
- Problem with my loops
- How to query most recent post for each author?
- Sorting query_posts() with a complex orderby filter
- Check the product in the cart from which category is and show message
- WP_Query showing all posts, except from category X, unless it’s also in Y
- I need query_posts() to order results first by a meta value and then by post ID
- Displaying Pages in Nav Sub-Menu with Specific Taxonomy Terms?
- WordPress For Loop Prints Unwanted Extra Paragraph Element
- Displaying posts from sub taxonomies only
- Single query for multiple categories
- How to search CPTs in draft using get_page_by_title()
- Taxonomy archive, categorised by other taxonomy, not hiding empty taxonomies
- Display 3 levels of categories on page
- Filtering ‘Featured’ posts from a batch of category IDs
- Show posts from categories instead of tags
- Multiple values in WP_Query : category__and
- How to show post title in content editor in backend?
- How to exclude posts by ID within a category/archive loop
- Optimal way to make tags in tax_query optional?
- Query the title of the page to show posts with matching category in the loop
- I have 3 categories, i want to display on a loop the last 3 of every category
- How to define a custom hierarchy for terms?
- Adding Category in WP_Query Not Working
- Orderby query does not work for custom fields even with meta query
- Merge two queries and remove duplicate
- How to order posts, that have already been filtered by custom taxonomy, by their category names?
- Taxonomy Terms That Don’t Exist Display Results
- How to add in WP_Query to every 3 posts displayed? [duplicate]
- Making Woocommerce optimized for more than 500k products
- Adding additional taxonomies to wordpress taxonomy page
- I cannot get tax_query in get_posts() to work with custom taxonomy
- display all posts from category with and without terms in chronological order
- Help displaying related categories
- How to create page that lists tags by initial letter?
- Seach and categories not working when ignoring sticky posts in main loop
- posts_per_page increment additional post
- Custom WP_query and integrating into theme file
- Query_post 5 post first / last of post_id
- how to avoid reloading/refresh the page when displaying the post of wp_list_categories
- Calling body_class and wp_nav_menu for a different post
- Category Archive not working for pages
- How can I get all the posts that are related with a specific taxonomy term?
- Show full category tree for a year with all post titles?
- How to combine nested tax_query logic with other nested query logic?
- query_posts() doesn’t seem to be called in my page
- Query Top Set Custom Taxonomy In Given Timeperiod
- Modify query to exclude certain ids and certain parents and its corresponding children
- Some doubts about how the main query and the custom query works in this custom theme?
- tax_query not working for taxonomy slug
- Retrieving category pages from subcategory returns empty sets
- Rewrite rule pagination on different url levels
- Fetching $_POST from Page Template into functions.php
- How to order by datediff in WP loop?
- Select posts wich has no relationship in custom taxonomy
- Custom query for tag and custom tag from 2 post type
- how to exclude store in clipper theme wordpress code php
- Ordering Posts by parent category, name ascending
- How to get hierarchical number of custom taxanomy
- query.php – multiple is_category functions
- Custom loop – Isolating post meta output depending on current query taxonomy terms
- WP_Query to show post from a category OR custom field – Not 100% answered
- Get newest value of an array
- Display Count of posts
- Filter custom post type by custom taxomony
- Create multiple sections for all categories and then queries all the posts for each of those categories
- WordPress custom post type
- Hiding all posts/products/pages from a site based on a custom taxonomy/domain name
- Display 2nd category, only once, as sub-heading, in the loop
- Optimising specific Query with ACF meta objects
- Page displaying 1st post from a range of custom tax?
- WordPress WP_Query Array Custom search via taxonomies
- How to organize a WP_Query’s list of posts by category and display category title?
- When should you use WP_Query vs query_posts() vs get_posts()?
- query_posts with sorting on a custom datestamp
- query post based on comparison
- How to query post ids liked by the Author
- Converting an existing query_posts to WP_Query