I want to make after the post other entries from the same category. But there is one more nuance, I created an arbitrary field, and there I indicate the IDs that I want them to output to it. Further I use WP_Query

$id = get_the_id(); $categories = get_the_category($id); $args = array( 'posts_per_page' => 4, 'category__in' => $cats_id, 'orderby' => 'rand', 'posts__not_in' => array($id) ); // Проверяю полученныя данные из проивольного поля if($related_to_this_post) { $args['post__in'] = $related_to_this_post; } 

So the problem is that if in an arbitrary field I specify only one id (entered into the $ related_to_this_post variable), then one is output, but I would like the rest of the IDs to be output randomly.

Is it possible to make it so that 4 posts are displayed anyway?

  • It is necessary to do 2 requests. The first is for posts__in, the second for random posts, in the amount of 4 minus the count in related. Then the results of the two queries combine and display the received 4 posts. I do not see any other way. - KAGG Design
  • Do you mean to unite them at the stage of creating an array of arguments? Before creating a new WP_Query object? - Vlad
  • Not. Make the first request, save the result. Then the second - KAGG Design

0