categories - What's the difference between "parent" and "category_parent" in a WP_Te

admin2025-06-05  0

What's the difference between "parent" and "category_parent" in a WP_Term object? For example:

[1] => WP_Term Object
    (
        [term_id] => 24
        [name] => Essential Oils
        [slug] => essential-oils
        [term_group] => 0
        [term_taxonomy_id] => 24
        [taxonomy] => category
        [description] => 
        [parent] => 22
        [count] => 14
        [filter] => raw
        [cat_ID] => 24
        [category_count] => 14
        [category_description] => 
        [cat_name] => Essential Oils
        [category_nicename] => essential-oils
        [category_parent] => 22
    )

What's the difference between "parent" and "category_parent" in a WP_Term object? For example:

[1] => WP_Term Object
    (
        [term_id] => 24
        [name] => Essential Oils
        [slug] => essential-oils
        [term_group] => 0
        [term_taxonomy_id] => 24
        [taxonomy] => category
        [description] => 
        [parent] => 22
        [count] => 14
        [filter] => raw
        [cat_ID] => 24
        [category_count] => 14
        [category_description] => 
        [cat_name] => Essential Oils
        [category_nicename] => essential-oils
        [category_parent] => 22
    )
Share Improve this question asked Dec 4, 2018 at 22:45 scott8035scott8035 2302 silver badges10 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

The properties prefixed with category_ or cat_ are there for backwards compatibility.

Taxonomies and terms were introduced in WordPress 2.3 (11 years ago) and categories were converted into a taxonomy at that time. Prior to this categories had their own properties (the ones with the aforementioned prefixes).

For backwards compatibility, the _make_cat_compat() function is used in some places to add the old properties to categories. You can see from the source that all it does is copy the standard term properties to the old names, so parent and category_parent will always have the same value, as an example.

In 2018 you should avoid using the category-specific properties.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749128584a316606.html

最新回复(0)