[wp-trac] [WordPress Trac] #29663: next_post_link & previous_post_link Category exclude broken
WordPress Trac
noreply at wordpress.org
Tue Sep 16 06:11:05 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 gabrieldiggs):
Replying to [comment:5 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() 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.
Thanks for taking a further look. According to FileMerge the major
difference regarding get_next/previous_post_link & next/previous_post_link
is for 3.9.2 it uses the parameter: $in_same_cat and for 4.0 it replaced
all instances of that parameter with the parameter: $in_same_term
Perhaps that is what's wrong with my site. I'm not sure how to fix the
problem beyond sticking to the 3.9.2 version. Any tips are much
appreciated.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/29663#comment:6>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list