wordpress rest api v2 how to list taxonomy terms?

后端 未结 7 1844
情歌与酒
情歌与酒 2021-02-15 11:23

i am new to v2, i use v1 for long time, currently upgrade to v2, i try to get all the terms belong to specific custom taxonomy.

In v1 i can do this to get terms /taxonom

7条回答
  •  别那么骄傲
    2021-02-15 11:57

    If anyone is reading this in the future, I ran into an issue where the default WP category was outputting a parent key of 0, 1, 2 etc for each term object, which is a problem in itself, but a bigger problem when custom taxonomies do not have this parent value on objects

    To solve this amend the ticked example with this:

        foreach ($taxonomies as $key => $taxonomy_name) {
            if($taxonomy_name = $_GET['term']){
                $return = get_terms( array( 
                    'taxonomy' => $taxonomy_name,
                    'hide_empty' => false,
                ));
            }
        }
    

提交回复
热议问题