D
D
Denis Kiselev2021-06-12 19:50:14
WordPress
Denis Kiselev, 2021-06-12 19:50:14

WP_query does not work correctly in front-page.php template. how to find the reason?

Greetings!
there is a code:

//посты которые исключить
$community_not_in_query = new WP_Query([
  'post_type' => 'post', 
  'posts_per_page' => -1,
  'editors' => 'community', 
  'fields' => 'ids',
  'meta_query' => 
]);
$community_not_in = $community_not_in_query->posts;

$args = array (
    'post_type'              => array( 'post' , 'event'),
    'posts_per_page'         => 30,
    'ignore_sticky_posts'    => false,
    'post__not_in'           => $community_not_in
);

$query = new WP_Query( $args );
if ( $query->have_posts() ) : 
    while ( $query->have_posts() ) : $query->the_post();
        echo get_the_title().'</br>';
    endwhile;
endif; 
wp_reset_postdata();

the first request generates an array with id. posts, in the second we generate a feed of posts and exclude posts from the feed using the "post__not_in" parameter. So this code does not work in the front-page.php template, unnecessary posts still end up in the feed. The most interesting thing is that if the same code is run on any other page (for example, page-[single].php), then everything works correctly.

Tell me, what could be the reason for such a bug, the second day I'm racking my brain(

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question