[wp-trac] [WordPress Trac] #27564: previous_post_link() and next_post_link() returns nothing

WordPress Trac noreply at wordpress.org
Fri Mar 28 06:49:50 UTC 2014


#27564: previous_post_link() and next_post_link() returns nothing
--------------------------+-----------------------
 Reporter:  genkisan      |       Owner:
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  3.9
Component:  Themes        |     Version:  trunk
 Severity:  normal        |  Resolution:
 Keywords:  has-patch     |     Focuses:  template
--------------------------+-----------------------

Comment (by genkisan):

 Patch works for case 2. Thanks!

 My bad for case 1. It was caused by the pre_get_posts action in my
 functions.php to exclude some categories.

 {{{
 function my_pre_get_posts($query) {
         $query->set('cat', '-4');
         return $query;
 }
 add_action('pre_get_posts', 'my_pre_get_posts');
 }}}

 So when the in_same_cat parameter is true, the prev/next links are not
 displayed (in the single post under that category). I got it to work with
 a remove_action:

 {{{
 remove_action('pre_get_posts', 'my_pre_get_posts');
 previous_post_link( '%link', __( '<span class="meta-nav">Previous
 Post</span>%title', 'twentyfourteen' ), true );
 next_post_link( '%link', __( '<span class="meta-nav">Next
 Post</span>%title', 'twentyfourteen' ), true );
 }}}

 Seems like the pre_get_posts action is applied in WP 3.9 though not in WP
 3.8.1. Not sure if that's the intended behavior. If it is then I will just
 use the remove_action as above :)

--
Ticket URL: <https://core.trac.wordpress.org/ticket/27564#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list