Мне нужно получать похожие посты только в определенных категориях. Но массив 'post__not_in' => (get_the_ID (), 4) не работает.
<?php
$cats_to_ignore = array(get_the_ID(), 4);
$categories = wp_get_post_categories( get_the_ID() );
$category_in = array_diff( $categories, $cats_to_ignore );
if( count( $category_in ) == 0 ) {
$category_in = $categories;
}
$cat_args = array(
'category__in' => $category_in,
'posts_per_page' => 14,
'orderby' => 'date',
'post__not_in' => array(get_the_ID(), 4)
);
$cat_query = new WP_Query( $cat_args );
while ( $cat_query->have_posts() ) : $cat_query->the_post();
/* just example markup for related posts */
echo '<h2><a href="' . get_the_permalink() . '">' . get_the_title() . '</a></h2>';
endwhile;
// reset $post after custom loop ends (if you need the main loop after this point)
wp_reset_postdata(); ?>
Он покажет все сообщения, связанные, но не исключая категорию в 'post__not_in'