Answer the question
In order to leave comments, you need to log in
Why does pagination not work and pages ../page/2 do not work in wordpress?
I created a custom type of post "Hot tour", you need to display all his posts on the page page by page.
Pagination is not displayed.
<?php
global $wp_query;
$page = get_query_var('paged');
$args = array (
'post_type' => 'hot-tour',
'posts_per_page' => '2',
'paged' => $page,
);
$custom_query = new WP_Query( $args );
if ( $custom_query->have_posts() ) {
while ( $custom_query->have_posts() ) {
$custom_query->the_post();
the_title();
}
}
posts_nav_link()
?>
<?php get_footer() ;?>
register_post_type( 'hot-tour', [
'label' => 'Горящий тур',
'public' => true,
'menu_position' => 4,
'supports' => ['title' ,'thumbnail', 'custom-fields' ], // 'title','editor','author','thumbnail','excerpt','trackbacks','custom-fields','comments','revisions','page-attributes','post-formats'
'has_archive' => true,
] );
Answer the question
In order to leave comments, you need to log in
$query = new WP_Query([
'post_type' => 'hot-tour',
'posts_per_page' => 2,
'paged' => get_query_var('page'),
]);
if ($query->have_posts()) {
while ($query->have_posts()) {
$query->the_post();
the_title();
}
wp_reset_postdata();
}
// Выводим пагинацию
echo paginate_links([
'base' => user_trailingslashit(wp_normalize_path(get_permalink() . '/%#%/')),
'current' => max(1, get_query_var('page')),
'total' => $query->max_num_pages,
]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question