R
R
ragnar_ok2018-07-13 14:03:33
WordPress
ragnar_ok, 2018-07-13 14:03:33

Why is pagination not working correctly (WordPress)?

Pagination does not work correctly on the page . Ten pages are displayed. At the same time, the transition to the tenth does not display posts. After switching to the second, the tenth number disappears. This is done using the native function . Used the code in funtions.php and it partially helped:<? Php the_posts_pagination ($ args); ?>

function site_request($query_string ) {
  if ( isset( $query_string['page'] ) ) {
    if ( ''!=$query_string['page'] ) {
      if ( isset( $query_string['name'] ) ) {
        unset( $query_string['name'] ); }
      }
    }
    return $query_string;
}
add_filter('request', 'site_request');

add_action('pre_get_posts', 'site_pre_get_posts');
function site_pre_get_posts( $query ) {
  if ( $query->is_main_query() && !$query->is_feed() && !is_admin() ) {
    $query->set( 'paged', str_replace( '/', '', get_query_var( 'page' ) ) );
  }
}

As I found out, this problem occurs when permalinks are set to something like this:
/%category%/%postname%/
However, now when you click on the tenth page number, it displays the contents of the ninth page. And also after the transition to the second, the tenth number disappears. What to do?

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