I have similar posts uploaded. I added more pages.
'post_type' => array('post','page') Began to display all pages including unnecessary, such as "contacts" and so on. I added
'exclude' => '12,14,21,23' , but no sense they are also loaded, not excluded.
Where is the mistake? why exclude doesn't work?
add_action('wp_ajax_get_related_posts', 'get_related_posts'); add_action('wp_ajax_nopriv_get_related_posts', 'get_related_posts'); function get_related_posts() { $post__not_in = $_POST['post__not_in']; $category__in = $_POST['category__in']; $args = array('post__not_in' => $post__not_in, 'category__in' => $category__in, 'posts_per_page' => 3, 'post_status' => 'publish', 'orderby' => 'rand', 'post_type' => array('post','page'), 'exclude' => array(12,14,21,23)); $query = new WP_Query($args); if ($query->have_posts()) : ?> <div class="related-posts-block clearfix"> <?php while ($query->have_posts()) : $query->the_post(); ?> <div class="related-post" data-post-id="<?php the_ID(); ?>"> <a href="<?php the_permalink(); ?>" target="_blank"> <?php if (has_post_thumbnail()) { the_post_thumbnail('s320x160'); } else { ?> <img src="//placehold.it/250x125"> <?php } ?> <div class="related-post-title"> <span><?php the_title(); ?></span> </div> </a> </div> <?php endwhile; wp_reset_postdata(); ?> </div> <?php endif; die(); }