[wp-trac] [WordPress Trac] #55358: Passing int term term_exists parent param not respected

WordPress Trac noreply at wordpress.org
Tue Jan 28 03:17:30 UTC 2025


#55358: Passing int term term_exists parent param not respected
-------------------------------------------------+-------------------------
 Reporter:  spacedmonkey                         |       Owner:  (none)
     Type:  defect (bug)                         |      Status:  new
 Priority:  normal                               |   Milestone:  Future
                                                 |  Release
Component:  Taxonomy                             |     Version:
 Severity:  normal                               |  Resolution:
 Keywords:  good-first-bug has-patch needs-      |     Focuses:
  testing                                        |
-------------------------------------------------+-------------------------

Comment (by spacedmonkey):

 @thehercules Sorry for the late reply.

 Looking at your PR. How about instead of adding

 {{{#!php
 if ( ! empty( $taxonomy ) && is_numeric( $parent_term ) ) {
                         $args['parent'] = (int) $parent_term;
 }

 }}}
 into the `if ( is_int( $term ) ) {` statement. Move it before like this.

 {{{#!php
 $defaults = apply_filters( 'term_exists_default_query_args', $defaults,
 $term, $taxonomy, $parent_term );

 if ( ! empty( $taxonomy ) && is_numeric( $parent_term ) ) {
                         $args['parent'] = (int) $parent_term;
 }

 if ( is_int( $term ) ) {

 }}}

 that way you would not have repeated logic.

 I would like to see a unit test here if possible as well. Thanks for your
 contribution.

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


More information about the wp-trac mailing list