Answer the question
In order to leave comments, you need to log in
How to fix pagination in Wordpress?
The content of the page of the custom post type does not change when switching pages to through pagination.
The pagination itself in the archive-mebel.php file:
<?php
$page = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts( array(
'post_type' => 'mebel',
'posts_per_page' => 2,
'paged' => $paged
) );
$current_page = $page; ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php echo the_title(); ?>
<?php endwhile; ?>
<?php the_posts_pagination( array(
'prev_text' => '« Назад',
'next_text' => 'Вперед »',
'screen_reader_text' => 'Страницы: ',
'current' => $current_page
) );
wp_reset_query(); ?>
function codernote_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', 'codernote_request');
add_action('pre_get_posts', 'codernote_pre_get_posts');
function codernote_pre_get_posts( $query ) {
if ( $query->is_main_query() && !$query->is_feed() && !is_admin() ) {
$query->set( 'paged', str_replace( '/', '', get_query_var( 'page' ) ) );
}
}
Answer the question
In order to leave comments, you need to log in
Try this one, it works for me
<?php
$custom_query_args = array(
'post_type'=>'mebel',
'posts_per_page' => 2
);
$custom_query_args['paged'] = get_query_var( 'page' ) ? get_query_var( 'page' ) : 1;
$custom_query = new WP_Query( $custom_query_args );
$temp_query = $wp_query;
$wp_query = NULL;
$wp_query = $custom_query;
if ( $custom_query->have_posts() ) :
while ( $custom_query->have_posts() ) :
$custom_query->the_post();
echo the_title();
endwhile;
endif;
wp_reset_postdata();
$args = array(
'prev_text' => '« Назад',
'next_text' => 'Вперед »',
'screen_reader_text' => 'Страницы: '
);
the_posts_pagination($args);
$wp_query = NULL;
$wp_query = $temp_query;
?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question