[wp-trac] [WordPress Trac] #22112: get_adjacent_post excluded_categories isn't excluded

WordPress Trac noreply at wordpress.org
Fri Feb 21 17:18:37 UTC 2014


#22112: get_adjacent_post excluded_categories isn't excluded
-------------------------------+------------------------------
 Reporter:  PatNarciso         |       Owner:
     Type:  defect (bug)       |      Status:  new
 Priority:  normal             |   Milestone:  Awaiting Review
Component:  Posts, Post Types  |     Version:  3.8.1
 Severity:  normal             |  Resolution:
 Keywords:  2nd-opinion        |     Focuses:  template
-------------------------------+------------------------------
Changes (by jessepollak):

 * keywords:   => 2nd-opinion
 * version:   => 3.8.1


Comment:

 Thanks for the bug report PatNarciso (and a belated-congrats on your first
 one!), sorry you never got a response!

 I just confirmed that this bug is still around in trunk at revision 27076
 (though the code has changed since he made the bug report, so things look
 a little different).

 To recreate:

 1. Create a three new posts Post 1, Post 2, and Post 3.
 2. Give both Post 1 and Post 2 a category of "bad" and give both Post 1
 and Post 3 a category of "good"
 3. Run

 {{{
 global $post;
 $post = POST_1_ID;
 $adjacent_post = get_adjacent_post(
     true, // in the same category
     'ID_OF_BAD_CATEGORY', // exclude the test category
     false // should be the next rather than previous post
 );
 }}}

 '''Expected:'''

 This should return Post 3 because, while Post 2 is in the same category as
 Post 1, it has the excluded_category "bad."

 '''Actual'''

 It returns Post 2 which has the excluded category "bad".

 '''Why'''

 This happens because, as PatNarciso reports, the $excluded_terms array is
 array_diff'd with the $term_array of acceptable terms. This means that any
 category that the both the post has ''and'' is excluded, will be included.

 I think this fix should be as easy as just removing the array_diff line at
 1167 — it doesn't seem to serve any purpose but to create this error case.
 That said, this may not be an error case ''and'' this fix will have an
 affect on the "next" link of a whole lot of blogs, so I'm not sure it's
 something we want to patch.

 I'll defer to core members on whether this is something we want to fix —
 if so, I'd be happy to write the quick patch for it.

 Thanks again PatNarciso!

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


More information about the wp-trac mailing list