Note that there are some explanatory texts on larger screens.

plurals
  1. POwordpress custom post type pagination -- previous posts link showing when no previous posts exist
    primarykey
    data
    text
    <p>Lots of questions about custom post types and pagination, but as far as I can find, no-one else with this problem:</p> <ul> <li>Post type created -- check </li> <li>new query for custom archive page -- check </li> <li>page one totally loads correctly -- check </li> <li>page two shows posts it should -- check. BUT: it also still has the <strong>previous posts</strong> link. </li> <li>which point to page three, even though there are no posts to display</li> </ul> <p>The problem: post navigation still shows on page two, allowing for a click to page 3 (4, 5, 6 etc) -- where there are no posts. No 404, just a blank page, as though the loop is still looping through an infinite sea of nothingness. </p> <p>Code:</p> <pre><code>&lt;?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $loop = new WP_Query( array( 'post_type' =&gt; 'portfolio', 'posts_per_page' =&gt; 10, 'paged'=&gt;$paged ) ); ?&gt; &lt;?php while ( $loop-&gt;have_posts() ) : $loop-&gt;the_post(); ?&gt; &lt;article &gt; /*stuff in here */ &lt;/article&gt; &lt;?php endwhile; ?&gt; &lt;div id="post-navigation"&gt; &lt;div class="nav-previous"&gt;&lt;?php next_posts_link(__( 'Previous Projects' )) ?&gt;&lt;/div&gt; &lt;div class="nav-next"&gt;&lt;?php previous_posts_link(__( 'Next Projects' )) ?&gt;&lt;/div&gt; &lt;/div&gt;&lt;!-- #post-navigation --&gt; </code></pre> <p>Other info: I'm displaying this with archive-portfolio.php -- no blank page to muddy up permalinks. </p> <p>On page 1, there's no option for next post -- so that half seems to be working, but previous just lets me go back in time forever, where there are no posts to display. </p> <p>Many thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload