Josan
Josan

Reputation: 722

Why next_post_link have to call twice in order to function?

I'm creating the pre/next posts navigator using the following code in wordpress 4.8 and php 7:

<span class="nav-previous"><?php previous_post_link('&laquo; %link', '%title', true); ?></span>
<span class="nav-next"><?php next_post_link('%link &raquo;', '%title', true); ?></span> 

The previous link works well, but the next link never displayed.

Then I tried the following code:

<span class="nav-previous"><?php previous_post_link('&laquo; %link', '%title', true); ?></span>
<?php next_post_link('%link &raquo;', '%title', true); ?>
<span class="nav-next"><?php next_post_link('%link &raquo;', '%title', true); ?></span> 

It calls next_post_link twice, and now it works as expected. However, this solution is simple and ugly. I beleive there is something wrong with my code or wordpress settings.

Here is the whole malfunction code snippet:

<?php if ( array_intersect($excluded_terms, $categories_id_list) ) { ?>
    <span class="nav-previous"><?php previous_post_link('&laquo; %link', '%title', true); ?></span>
    <span class="nav-next"><?php next_post_link('%link &raquo;', '%title', true); ?></span> 
<?php } else { ?>
    <span class="nav-previous"><?php previous_post_link('&laquo; %link', '%title', false, $excluded_terms); ?></span>
    <span class="nav-next"><?php next_post_link('%link &raquo;', '%title', false, $excluded_terms); ?></span>
<?php } ?>

Only previous_post_link shows correctly.

Here is a list of installed and enable plugins on my site:

Any suggestion would appreicate.

Upvotes: 1

Views: 71

Answers (1)

Josan
Josan

Reputation: 722

I disabled the Book Review Library plugin, then it fixes.

Upvotes: 1

Related Questions