您的当前位置:首页 > 知识博客 > wordpress建站

WordPress获取文章元数据键函数:get_post_custom_keys

时间:2024-03-09

WordPress函数get_post_custom_keys用于获取文章所有元数据的键。

get_post_custom_keys( int $post_id )

函数参数

$post_id

整数,默认值:当前文章ID

文章的ID

函数返回值

文章的自定义字段不同,返回的结果也有所不同:

Array
(
    [0] => _edit_last
    [1] => _thumbnail_id
    [2] => _edit_lock
    [3] => views
    [4] => _wp_page_template
    [5] => _encloseme
)

函数使用示例

以下示例排除了系统自带的meta,也就是仅返回用户自定义字段:

$custom_field_keys = get_post_custom_keys();
foreach ( $custom_field_keys as $key => $value ) {
    $valuet = trim($value);
    if ( '_' == $valuet{0} )
        continue;
    echo $key . " => " . $value . "<br />";
}

扩展阅读

get_post_custom_keys()函数位于:wp-includes/post.php

相关函数:

  • get_post_custom()

  • get_post_custom_values()

  • the_meta()

  • get_post_meta()


欢迎咨询/Welcome to inquire
tel/vx:18842938855
qq:1685522781
email:1685522781@qq.com

Copyright © 2019-2024 ytldj.com


Whatsapp
Powered by RRZCMS