Pagination with custom post types results in 404 issues


I’ve a very simple index.php:

<div id="content">
  <? get_template_part('content', get_post_format()) ?>

<div id="pagination">
  <? previous_posts_link() ?>
  <? next_posts_link() ?>

And my content.php looks roughly like this:

$paged = get_query_var('paged') ? get_query_var('paged') : 1;
  'post_type' => ['articles', 'projects', 'tips'],
  'orderby' => 'date',
  'posts_per_page' => 7,
  'paged' => $paged

<? while(have_posts()): the_post() ?>
  <article class="post">
    <h2><? the_title() ?></h2>
    <p><? the_excerpt() ?></p>
      <? foreach($categories as $cat): ?>
      <li class="category"><a href="#"><?= $cat->name ?></a></li>
      <? endforeach ?>
<? endwhile ?>

There are 14 posts in total but the “next” posts is always redirecting to a 404 on /page/2 instead of showing the remaining 7 posts.

Edit: If I use a custom WP_Query instead of query_posts then the next and previous links won’t even show.

I’ve been trying to find a solution to this issue since yesterday. I’m aware of all the other questions similar to this one, but for my particular set-up none of the solutions I found worked, including:

I’m also aware of pre_get_posts but I would like to know what’s the problem with my current setup. Any ideas?

elclanrs 2 years 2020-12-17T04:10:28-05:00 0 Answers 7 views 0

Leave an answer