0

I tried to do pagination in my custom template page.

So I did a custom query, and put for having pagination.

The problem is when i tried to enter to http://mywebsite.com/slug-custom-page/page/2/

It automatically redirect to http://mywebsite.com/slug-custom-page/

So http://mywebsite.com/slug-custom-page/page/2/ automatically redirect to http://mywebsite.com/slug-custom-page/

That file is a custom template for a specific page.

However if i tried to enter to http://mywebsite.com/slug-custom-page/pagefsdfsdf/2/ it will not redirect to http://mywebsite.com/slug-custom-page/

But it shows me a 404 error

So I always get first results, how can I do to stop that redirection ?

My page file :

/*
Template Name: Page Infos 
*/

...... some codes ......

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
  'post_type' => 'post',
  'posts_per_page' => '12',
  'order' => 'DESC',
 'paged' => $paged
);
$wp_query = new WP_Query($args);
if (have_posts()) {
  $count = 0;
  while (have_posts()) {


...... some codes ......

<?php echo paginate_links(); ?>

In dashboard -> permalinks, I use : Common Settings , as website/%postname%/

When I see in chrome dev tools, i see that it's a 301 redirection

But if i use in permalink setting "Plain" i get ?paged=2&page_id=712 and no more redirection

But i dont want to have that kind of permalink, i want to use website/%postname%/

Thank you

  • When you say you did a custom query can you share with us the code? Did you modify the main query via the pre_get_posts filter? Or did you replace it with a brand new query and discard the original? Or is this a secondary query for a subsection of the page? There's very little that can be done to diagnose the issue if all we have are URLs :( use the edit link under the tags to update your question with as much information as possible, even if it's just to say you don't know the answer to one of the questions – Tom J Nowell Dec 27 '19 at 13:55
  • thanks for reply, I just edited my question.. it's a new query to get some posts – user3134277 Dec 27 '19 at 14:00
  • When I see in chrome dev tools, i see that it's a 301 redirection – user3134277 Dec 27 '19 at 14:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.