how display related posts first by tags then by categories?

Question

this is my code:

$q = new WP_Query(
array(
'posts_per_page'=>3,
'tag__in'=>$post_tags,
'category__in'=>$post_categories,
'post__not_in'=>array(get_the_id())
)
);

i want display related posts based tags and then if there is no posts based on tags, then displayed based on categories!
there is some way to do this?

0
Mohammad 3 months 0 Answers 12 views 0

Leave an answer