最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

What is the "meta" key in WP_Term Object?

programmeradmin3浏览0评论

I thought it would be term meta but that doesn't seem to be correct.

For illustration I've created a category named "Test" with a slug of "test".

I'm updating its term_meta with:

update_term_meta( 64, 'test_meta', 'asdfasdf' );

This appears in the termmeta table along with other meta keys/values:

get_term(64) returns this:

WP_Term Object
(
    [term_id] => 64
    [name] => Test
    [slug] => test
    [term_group] => 0
    [term_taxonomy_id] => 64
    [taxonomy] => category
    [description] => 
    [parent] => 0
    [count] => 0
    [filter] => raw
    [meta] => Array
        (
        )

)

Why is [meta] empty?

get_term_meta(64) returns as expected:

Array
(
[headline] => Array
    (
        [0] => 
    )

[intro_text] => Array
    (
        [0] => 
    )

[display_title] => Array
    (
        [0] => 0
    )

[display_description] => Array
    (
        [0] => 0
    )

[doctitle] => Array
    (
        [0] => 
    )

[description] => Array
    (
        [0] => Meta desc
    )

[keywords] => Array
    (
        [0] => someMetaKeyword
    )

[layout] => Array
    (
        [0] => 
    )

[noindex] => Array
    (
        [0] => 0
    )

[nofollow] => Array
    (
        [0] => 0
    )

[noarchive] => Array
    (
        [0] => 0
    )

[test_meta] => Array
    (
        [0] => asdfasdf
    )

)

I thought it would be term meta but that doesn't seem to be correct.

For illustration I've created a category named "Test" with a slug of "test".

I'm updating its term_meta with:

update_term_meta( 64, 'test_meta', 'asdfasdf' );

This appears in the termmeta table along with other meta keys/values:

get_term(64) returns this:

WP_Term Object
(
    [term_id] => 64
    [name] => Test
    [slug] => test
    [term_group] => 0
    [term_taxonomy_id] => 64
    [taxonomy] => category
    [description] => 
    [parent] => 0
    [count] => 0
    [filter] => raw
    [meta] => Array
        (
        )

)

Why is [meta] empty?

get_term_meta(64) returns as expected:

Array
(
[headline] => Array
    (
        [0] => 
    )

[intro_text] => Array
    (
        [0] => 
    )

[display_title] => Array
    (
        [0] => 0
    )

[display_description] => Array
    (
        [0] => 0
    )

[doctitle] => Array
    (
        [0] => 
    )

[description] => Array
    (
        [0] => Meta desc
    )

[keywords] => Array
    (
        [0] => someMetaKeyword
    )

[layout] => Array
    (
        [0] => 
    )

[noindex] => Array
    (
        [0] => 0
    )

[nofollow] => Array
    (
        [0] => 0
    )

[noarchive] => Array
    (
        [0] => 0
    )

[test_meta] => Array
    (
        [0] => asdfasdf
    )

)
Share Improve this question asked Jun 15, 2019 at 18:14 Ken DeWittKen DeWitt 133 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

Looking at the source, that meta property isn't a standard property in the WP_Term object.

However, a plugin/theme can add custom properties to the object using the get_term or get_{taxonomy} filter:

add_filter( 'get_term', function( $term ){
    $term->meta = get_term_meta( $term->term_id ); // all metadata
    return $term;
} );
发布评论

评论列表(0)

  1. 暂无评论