Make WordPress Core

Opened 8 months ago

Last modified 8 months ago

#59503 assigned enhancement

Multiple Parent Term Id parameter in get_terms

Reported by: plugindevs's profile plugindevs Owned by: plugindevs's profile < plugindevs>
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Taxonomy Keywords: has-patch
Focuses: Cc:

Description

Currently, there is no option to get child terms of multiple parent terms. There is a
'parent' parameter that returns child terms of only one parent term.

There is a 'post parent in' parameter for 'WP_Query' and 'get_posts()' to get child posts of multiple parent posts, but there is no similar parameter for 'WP_Term_Query', and 'get_terms()'.

So, I suggest a new parameter 'parents in' to get child terms from multiple parent terms IDs. The parameter on get_terms() will be like below:

<?php
    /**
     *
     *  @type int[] $parents__in 
     *  Array of comma-separated parent terms ID to retrieve child terms of given array.
     *  Default empty array.
     *
     */
    get_terms( array(
        'taxonomy'    => 'category',
        'parents__in' => array( 2, 3, 4 )
    ) );

Change History (1)

This ticket was mentioned in PR #5352 on WordPress/wordpress-develop by @plugindevs.


8 months ago
#1

Currently, there is no option to get child terms of multiple parent terms. There is a 'parent' parameter that returns child terms of only one parent term.
There is a 'post_parent__in' parameter for 'WP_Query' and 'get_posts()' to get child posts of multiple parent posts, but there is no similar parameter for 'WP_Term_Query', and 'get_terms()'.
So, I suggest a new parameter 'parents__in' to get child terms from multiple parent terms IDs. The parameter on get_terms() will be like below:

<?php
    /**
     *
     *  @type int[] $parents__in 
     *  Array of comma-separated parent terms ID to retrieve child terms of given array.
     *  Default empty array.
     *
     */
    get_terms( array(
        'taxonomy'    => 'category',
        'parents__in' => array( 2, 3, 4 )
    ) );

Trac ticket: https://core.trac.wordpress.org/ticket/59503

Note: See TracTickets for help on using tickets.