[wp-trac] [WordPress Trac] #29663: next_post_link & previous_post_link Category exclude broken

WordPress Trac noreply at wordpress.org
Mon Sep 15 18:41:46 UTC 2014


#29663: next_post_link & previous_post_link Category exclude broken
--------------------------+------------------------------
 Reporter:  gabrieldiggs  |       Owner:
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  General       |     Version:  4.0
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:
--------------------------+------------------------------

Comment (by kaprice):

 I put this line in one of my pages:
 {{{
 next_post_link( '%link', '%title', true, '3');
 }}}
 This page had categories 2 and 3. I went to the page using the same
 database using link-template.php from 3.9.2 and 4.0. I logged the mySQL
 queries for both. next_post_link() calls get_adjacent_post_link() where
 the database queries are made.

 Here are the differences in the queries:

 From 3.9.2

 {{{
 SELECT p.ID FROM wp_posts AS p  INNER JOIN wp_term_relationships AS tr ON
 p.ID = tr.object_id
   INNER JOIN wp_term_taxonomy tt ON tr.term_taxonomy_id =
 tt.term_taxonomy_id
   AND tt.taxonomy = 'category' AND tt.term_id IN (3,2) WHERE p.post_date >
 '2014-09-14 03:51:26'
   AND p.post_type = 'post' AND p.post_status = 'publish'  ORDER BY
 p.post_date ASC LIMIT 1
 }}}

 From 4.0:

 {{{
 SELECT p.ID FROM wp_posts AS p  INNER JOIN wp_term_relationships AS tr ON
 p.ID = tr.object_id
   INNER JOIN wp_term_taxonomy tt ON tr.term_taxonomy_id =
 tt.term_taxonomy_id
   WHERE p.post_date > '2014-09-14 03:51:26' AND p.post_type = 'post' AND
 p.post_status =
   'publish' AND tt.taxonomy = 'category' AND tt.term_id IN (2) AND p.ID
 NOT IN ( SELECT
   object_id FROM wp_term_relationships WHERE term_taxonomy_id IN (3) )
 ORDER BY p.post_date ASC
   LIMIT 1
 }}}

 The queries reflect the change in the php code for both versions of link-
 template.php. I don't know exactly what's wrong in your case, but using
 both versions had worked fine with me.

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


More information about the wp-trac mailing list