Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi,

    Thanks for the add on.

    Could You please add the function to get the taxonomies by parent?

    e.g parent=0 or parent=1

    Thanks,
    Alex

    Thread Starter Einkoro

    (@einkoro)

    You can use get_terms to fetch the children of a term for categories like this:
    /api/terms/get_terms/?taxonomy=category&term_args[parent]=my_parent_term_id

    If you want all children of a term (sub categories of sub categories) rather than direct children you can use this:
    /api/terms/get_terms/?taxonomy=category&term_args[child]=my_parent_term_id

    To fetch the parent of a term you can use get_term twice:
    /api/terms/get_term/?term_id=my_term_id&taxonomy=category

    Then with the parent from the previous term’s data you can call it again:
    /api/terms/get_term/?term_id=my_parent_term_id&taxonomy=category

    I could add a shortcut such as get_term_parent to only do one call for parents even though there is no equivalent in WordPress’s API if you’d like.

    Hi Einkoro,

    Thanks for reply. Yes, I got it but there is some problem. I have 16 categories but it only return 3 categories. I

    https://www.myhost.com/api/terms/get_terms/?taxonomy=ad_cat&term_args%5Bparent%5D=0

    Another example
    I have 12 sub categories but it is only return 2. Yes I only have post for those sub categories.
    https://www.myhost.com/api/terms/get_terms/?taxonomy=ad_cat&term_args%5Bparent%5D=18

    Regards,
    Alex

    Thread Starter Einkoro

    (@einkoro)

    If you add &term_args[hide_empty]=0 do you get the expected number of categories? By default get_terms will hide any terms without posts associated with them.

    Thanks Einkoro,

    I got the expected result. Great Add On. Save alot of my time.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Added Terms controller to fetch terms by taxonomy or post’ is closed to new replies.