Site icon Hip-Hop Website Design and Development

Rest Api How to get results of child categories with one api call

Example:

If I have a parent category 1 with child categories 2,3,4 etc

instead of a call like this:

/wp/v2/posts?categories=1,2,3,4

i want a call like this (imaging code)

/wp/v2/posts?categories=1&includeallchilds=true

that will include all articles from the child and sub-child of 1.

how is this possible? I don’t want my application make 2 api calls to find all childs of the categories of 1..

this query can done what i need, but i cant include this on rest api call,

$args = array(
    'post_type' => 'post',
    'order' => 'DESC',
    'posts_per_page' => 100,
    'tax_query' => array(
        array(
            'taxonomy' => 'category',
            'field'    => 'term_id',
            'terms'    => '1',
        ),
    ),
);