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

WordPress Trac noreply at wordpress.org
Sat Feb 22 05:46:10 UTC 2014


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

 * keywords:  2nd-opinion => 2nd-opinion has-patch dev-feedback


Comment:

 So, I started off by implementing the solution above, but quickly realized
 that it was insufficient. Removing that {{{array_diff}}} leaves the
 possibility that we'll have a query that selects posts which are both
 {{{IN}}} and {{{NOT IN}}} a given {{{term}}}. While discovering the
 problem with that solution, I also discovered that ''any time'' both
 {{{same_term}}} and {{{excluded_terms}}} are used in
 {{{get_adjacent_post}}}, we generate a query with both an {{{IN}}} and a
 {{{NOT IN}}} statement — a little redundant.

 In the patch below, I take the following approach:

 1. I get the {{${excluded_terms}}} and {{{$same_term_array}}}.
 2. I call {{{$same_term_array = array_diff($same_term_array,
 $excluded_terms)}}}, which removes all excluded terms from the
 {{{$same_term_array}}}
 3. If the {{{$same_term_array}}} is not empty, I add an {{{AND IN}}} for
 the {{{$same_term_array}}}
 4. If the {{{$same_term_array}}} is empty and the {{{$excluded_terms}}} is
 not empty, I add a {{{AND NOT IN}}} for the {{{$excluded_terms}}}

 Since both {{{IN}}} and {{{NOT IN}}} are exclusive, either step (4) or
 step (5) will ensure the adjacent post has the correct terms.

 I added a unit test to demonstrate this failure case and verify the patch.

 '''NOTE''': this change does affect the {{{get_$adjacent_post_where}}}
 filter, but I don't think it should be a problem — would appreciate
 feedback on this.

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


More information about the wp-trac mailing list