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.