T
T
Tiana2021-05-29 14:05:55
JavaScript
Tiana, 2021-05-29 14:05:55

Why does pagination work when hiding pinned posts in a loop?

9 posts are given
, 4 of them are attached and are displayed by a separate request
, the rest of the posts should be displayed as usual with pagination of 6 pieces.

The loop displays 5 posts and a link appears to the second page, which shows an empty feed.
how to fix it?
logically, there is 1 more place for a post, and in general, pagination should not take into account attached articles when paginating,

the cycle code is as follows:

$sticky = get_option( 'sticky_posts' );
$paged  = get_query_var( 'paged' ) ?: 1;

$query  = new WP_Query( array(
  'ignore_sticky_posts' => 1,
  'post__not_in'        => $sticky,
  'posts_per_page'      => 6,
  'post_type' 		  => 'post',
  'paged'               => $paged
) );

  while( $query->have_posts() ){ $query->the_post();
    
    include ('parts/content-loop.php');
  }


upd: it was empirically found that post__not_in confuses pagination - no matter what gets there (just articles or sticks) - they are excluded from the request, and there is

nothing to do with pagination - it's not clear

yet upd2: it turned out that this is a known problem pagination when trying to exclude attached articles from the main loop or apply offset
Treated through the pre_get_posts function

For my task, it turned out to be easier to attach an arbitrary field to the post and use it to attach posts and multiple sorting

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
zendor, 2019-01-21
@capitals

Final UPD (if I understood everything correctly):

const results = year.map(inner =>
  years.reduce((a, c) => a.concat(c.filter((v, i) => v == inner[i]).length > 1 ? [c] : []), []));

For each array in year, matches are displayed in a separate array.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question