1

I have about 20-30 posts in a CPT, and when I click on a single post and use the next_post_link and prev_post_link functions it will only show a select 5 posts out of the 20-30... always the same 5 as well.. I can't for the life of me work out why!

I've tried limiting to taxonomies or categories but that just brings it down to 0 links.

Has anyone come across this?

EDIT: I'm using a very streamlined install... the only plugins are CPT UI for the Custom Post Type and ACF for the fields.

Here is my code for the single-books.php (Single CPT page) the url is site.com/books/book-name

<?php get_header(); ?>
<main role="main">
    <section>

    <?php if (have_posts()): while (have_posts()) : the_post(); ?>

        <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

            <div class="col3">
                <h1 class="title"><span><?php the_title(); ?></span></h1>
            </div>
            <div class="col3">
                <div class="cover">
                    <?php $cover = wp_get_attachment_image_src( get_field('cover_image'), 'book' ); ?>
                    <img src="<?php echo $cover[0]; ?>" alt="">
                </div>
            </div>
            <div class="col3">

            </div>

            <div class="clear"></div>

            <div class="col3">
                <span class="label">Author:</span>
                <span class="data"><?php the_field('author') ?></span>
                <span class="label">Publisher:</span>
                <span class="data"><?php the_field('publisher') ?></span>
                <span class="share">[ Share ]</span>
            </div>

            <div class="col3">
                <span class="label">Review</span>
                <span class="data"><?php the_content(); ?></span>
            </div>

            <div class="col3">
                <span class="label">Publication Date:</span>
                <span class="data"><?php the_field('publication_date') ?></span>
                <span class="label">Genre:</span>
                <span class="data"><?php echo get_the_term_list( $post->ID, 'genres', '', ', ', '' ) ?></span>
                <span class="label">Reviewer:</span>
                <span class="data"><?php echo get_the_term_list( $post->ID, 'staff', '', ', ', '' ) ?></span>
                <?php if (get_field('buy_link')) : ?><span class="buy"><a target="_blank" href="<?php the_field('buy_link') ?>">· Buy Now ·</a></span><?php endif; ?>
            </div>

            <div class="clear"></div>

            <div class="col3 align-right pagination">
                <?php previous_post_link( '%link', '&laquo Previous Book', FALSE ); ?>
            </div>

            <div class="col3">
                <hr>
            </div>

            <div class="col3 align-left pagination">
                <?php next_post_link( '%link', 'Next Book &raquo', FALSE ); ?>
            </div>

            <div class="clear"></div>

            <div class="spacer"></div>

        </article>

    <?php endwhile; ?>

    <?php endif; ?>

    </section>
</main>
  • Can you post the code you are using? Impossible to figure what can be happening without seeing some code. – cybmeta Jan 21 '15 at 6:50
  • There must be something in your theme or is a plugin causing this. This is not a failure of the function itself. Your problem is just too localized for anyone to help you. The only advice I can give is, turn debugging on, disble plugins and swirch to a bundled theme. If none of this work, back up your sire and reinstall wordpress. Also look out for custom queries on your single page that could affect this. Good luck – Pieter Goosen Jan 21 '15 at 6:51
  • @cybmeta - I've posted my code. – Seb Szocinski Jan 21 '15 at 22:10
  • What happens if you remove the FALSE at the end and just have next_post_link( '%link', 'Next Book &raquo' ) ? – Howdy_McGee Jan 21 '15 at 22:42
  • @Howdy_McGee Originally didn't have that so tried adding it and it didn't help. Thanks though. – Seb Szocinski Jan 21 '15 at 22:49
1

@Milo solved this one - It was because the posts were imported using an import plugin hence having all the same date bar a few that ticked over every second! All posts must have a unique date / time in order for next and prev links to work.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.