Вот функция:
функция example_cats_related_post() {
$post_id = get_the_ID();
$cat_ids = array();
$categories = get_the_category( $post_id );
if(!empty($categories) && is_wp_error($categories)):
foreach ($categories as $category):
array_push($cat_ids, $category->term_id);
endforeach;
endif;
$current_post_type = get_the_category($categories);
$query_args = array(
'category__in' => $cat_ids,
'post_type' => get_the_category($categories),
'post__not_in' => array($post_id),
'posts_per_page' => '3'
);
$related_cats_post = new WP_Query( $query_args );
if($related_cats_post->have_posts()):
while($related_cats_post->have_posts()): $related_cats_post->the_post(); ?>
-
|
[url=
Подробнее здесь: https://stackoverflow.com/questions/760 ... ry-of-page