[wp-trac] [WordPress Trac] #39494: Make it possible for taxonomy query to include children in REST API

WordPress Trac noreply at wordpress.org
Thu Jan 5 23:33:45 UTC 2017


#39494: Make it possible for taxonomy query to include children in REST API
-----------------------------+-----------------------------
 Reporter:  jason_the_adams  |      Owner:
     Type:  defect (bug)     |     Status:  new
 Priority:  normal           |  Milestone:  Awaiting Review
Component:  REST API         |    Version:
 Severity:  normal           |   Keywords:
  Focuses:  rest-api         |
-----------------------------+-----------------------------
 Greetings!

 Currently when a registered taxonomy is used it's assumed that
 include_children is false. That's a bummer as a useful bit of
 functionality is being cut out of the WordPress query.

 {{{#!php
 <?php
 if ( ! empty( $request[ $base ] ) ) {
         $query_args['tax_query'][] = array(
                 'taxonomy'         => $taxonomy->name,
                 'field'            => 'term_id',
                 'terms'            => $request[ $base ],
                 'include_children' => false,
         );
 }
 }}}

 What about making it possible for $request[$base] to either be a string
 and work as-is for backwards-compatibility, or an array with term_id and
 include_children indexes?

 As a potential solution:
 {{{#!php
 <?php
 if ( ! empty( $request[ $base ] ) ) {
     $terms = is_array($request[ $base ]) && isset($request[ $base ][
 'term_id' ]) ? (int) $request[ $base ][ 'term_id' ] : 0;
     $include_children = is_array($request[ $base ]) && isset($request[
 $base ][ 'include_children' ]) ? (bool) $request[ $base ][
 'include_children' ] : false;

     $query_args['tax_query'][] = array(
         'taxonomy'         => $taxonomy->name,
         'field'            => 'term_id',
         'terms'            => $terms,
         'include_children' => $include_children,
     );
 }
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/39494>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list