Created
October 25, 2017 08:39
-
-
Save ihorduchenko/c6764f8a45d2dd4ed1fbe3d28bed735f to your computer and use it in GitHub Desktop.
WP_Query of related posts by array of categories of current post
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$cats = wp_get_post_terms( get_the_ID(), 'category' ); | |
$cats_ids = array(); | |
foreach( $cats as $wpex_related_cat ) { | |
$cats_ids[] = $wpex_related_cat->term_id; | |
} | |
$args = array( | |
'post_type' => 'post', | |
'order' => 'ASC', | |
'posts_per_page' => '3', | |
'category__in' => $cats_ids, | |
'post__not_in' => array($post->ID) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment