Answer the question
In order to leave comments, you need to log in
Why is Wordpress pagination adding a post_name resulting in a 404 error?
Hello!
In general, everything is a bit confusing:
We have a page /articles/
with a working pagination, and a page /multimedia/
on which we get a 404 error when going to the pagination page.
If you copy the entire code from /articles/
to /multimedia/
- then /multimedia/
pagination still does not work :) Some kind of magic.
I noticed that on the working page the request looks like this:
SELECT wp_posts.* FROM wp_posts WHERE 1=1 AND (wp_posts.ID = '43') AND wp_posts.post_type = 'page' ORDER BY wp_posts.post_date DESC
SELECT wp_posts.* FROM wp_posts WHERE 1=1 AND wp_posts.post_name = 'page' AND wp_posts.post_type = 'multimedia' ORDER BY wp_posts.post_date DESC
wp_posts.post_name = 'page'
$global_wp_query = $wp_query;
$paged = get_query_var('paged') ? absint(get_query_var('paged')) : 1;
$wp_query = new WP_Query([
'posts_per_page' => 15,
'post_type' => 'post', // В мультимедиа здесь - multimedia.
// Пробовал добавлять это в запрос - ничего не менялось.
// 'post_name' => '',
// 'name' => '',
'paged' => $paged,
]);
while ($wp_query->have_posts()) : $wp_query->the_post();
// Манипуляции с выводом превью
endwhile; wp_reset_postdata();
// Ну и вывод самой пагинации.
the_posts_pagination([
'total' => $wp_query->max_num_pages,
'mid_size' => 3,
'prev_next' => true,
'prev_text' => '←',
'next_text' => '→',
]); $wp_query = $global_wp_query
functions.php
manipulations with pagination were made, except for changing the appearance:add_filter('navigation_markup_template', function ($template, $class) {
return
'<nav class="navigation %1$s" role="navigation">'.
' <div class="nav-links">%3$s</div>'.
'</nav>';
}, 10, 2);
/articles/
) works correctly, but /multimedia/
not on the other ( ) :)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question