Home > database >  what are difference between get_terms() and get_categories() in wordpress. I have a get_category and
what are difference between get_terms() and get_categories() in wordpress. I have a get_category and

Time:12-30

what are difference between get_terms() and get_categories() in wordpress. I have a get_category and get_terms as follows get_categories array of object

array(
    [0] => WP_Term Object
        (
            [term_id] => 2
            [name] => Breakfast
            [slug] => breakfast
            [term_group] => 0
            [term_taxonomy_id] => 2
            [taxonomy] => menu_category
            [description] => hello word
            [parent] => 0
            [count] => 4
            [filter] => raw
            [cat_ID] => 2
            [category_count] => 4
            [category_description] => hello word
            [cat_name] => Breakfast
            [category_nicename] => breakfast
            [category_parent] => 0
        )

    [1] => WP_Term Object
        (
            [term_id] => 4
            [name] => Dinner
            [slug] => dinner
            [term_group] => 0
            [term_taxonomy_id] => 4
            [taxonomy] => menu_category
            [description] => 
            [parent] => 0
            [count] => 4
            [filter] => raw
            [cat_ID] => 4
            [category_count] => 4
            [category_description] => 
            [cat_name] => Dinner
            [category_nicename] => dinner
            [category_parent] => 0
        )

    [2] => WP_Term Object
        (
            [term_id] => 3
            [name] => Lunch
            [slug] => lunch
            [term_group] => 0
            [term_taxonomy_id] => 3
            [taxonomy] => menu_category
            [description] => 
            [parent] => 0
            [count] => 4
            [filter] => raw
            [cat_ID] => 3
            [category_count] => 4
            [category_description] => 
            [cat_name] => Lunch
            [category_nicename] => lunch
            [category_parent] => 0
        )

)

//----------------------------------------------------------------------------------------------------------- get_terms array of object

Array
(
    [0] => WP_Term Object
        (
            [term_id] => 2
            [name] => Breakfast
            [slug] => breakfast
            [term_group] => 0
            [term_taxonomy_id] => 2
            [taxonomy] => menu_category
            [description] => hello word
            [parent] => 0
            [count] => 4
            [filter] => raw
        )

    [1] => WP_Term Object
        (
            [term_id] => 4
            [name] => Dinner
            [slug] => dinner
            [term_group] => 0
            [term_taxonomy_id] => 4
            [taxonomy] => menu_category
            [description] => 
            [parent] => 0
            [count] => 4
            [filter] => raw
        )

    [2] => WP_Term Object
        (
            [term_id] => 3
            [name] => Lunch
            [slug] => lunch
            [term_group] => 0
            [term_taxonomy_id] => 3
            [taxonomy] => menu_category
            [description] => 
            [parent] => 0
            [count] => 4
            [filter] => raw
        )

)

Yes I tried my way but I don't understand what is the difference between the two?

CodePudding user response:

get_categories() is a wrapper function for get_terms('category').

Being that get_terms() is the main function it has a few more arguments that can be passed to it.

In general wordpress has quite a few wrapper functions that make for less coding per se, but if you want full control you can use the main function. A lot of them take similar arguments and return the same things with little difference.

  • Related