^ 回到顶部
  • 人生没有定律,每个人都有自己的节奏
  • 本站wordpress建站教程均通过实践后发布,希望对你有帮助
  • 希望你的坚持,都是因为热爱,而不是因为不甘心
  • 8年wordpress建站经验,5星服务品质
  • 那些不愿意让你吃亏的人,才是真正值得你深交的人,也是值得你付出时间的人
  • 阿里云2核2g仅需86元/年

wordpress函数get_post_custom()用法示例

get_post_custom( int $post_id )

Retrieve post meta fields, based on post ID.


描述

The post meta fields are retrieved from the cache where possible, so the function is optimized to be called more than once.

新用户2核2g仅需86元/年    领取1153套模板    免费cdn流量包    ¥3188礼包


参数

$post_id

(int)
(Optional)
Post ID. Default is ID of the global $post.


返回值

(array) Post meta for the given post.


源代码

File: wp-includes/post.php

function get_post_custom( $post_id = 0 ) {
	$post_id = absint( $post_id );
	if ( ! $post_id )
		$post_id = get_the_ID();

	return get_post_meta( $post_id );
}

更新日志

Version 描述
1.2.0 Introduced.

相关函数

Uses

  • wp-includes/functions.php:
    absint()
  • wp-includes/post-template.php:
    get_the_ID()
  • wp-includes/post.php:
    get_post_meta()

Used By

  • wp-includes/feed.php:
    rss_enclosure()
  • wp-includes/feed.php:
    atom_enclosure()
  • wp-includes/post-template.php:
    post_custom()
  • wp-includes/post.php:
    get_enclosed()
  • wp-includes/post.php:
    get_post_custom_keys()
  • wp-includes/post.php:
    get_post_custom_values()
  • wp-includes/class-wp-xmlrpc-server.php:
    wp_xmlrpc_server::mw_getPost()
  • Show 2 more used by
    Hide more used by


  1. Skip to note content

    You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note

    Contributed by Codex

    Default Usage
    Use the following example to set a variable ($custom_fields) as a multidimensional array containing all custom fields of the current post.

    <?php $custom_fields = get_post_custom(); ?>

    Retrieving data from the array
    The following example will retrieve all custom field values with the key my_custom_field from post ID 72 (assuming there are three custom fields with this key, and the values are “dogs”, “47” and “This is another value”).

    <?php
    
      $custom_fields = get_post_custom(72);
      $my_custom_field = $custom_fields['my_custom_field'];
      foreach ( $my_custom_field as $key => $value ) {
        echo $key . " => " . $value . "<br />";
      }
    
    ?>

    0 => dogs
    1 => 47
    2 => This is another value

    Note: not only does the function return a multi-dimensional array (ie: always be prepared to deal with an array of arrays, even if expecting array of single values), but it also returns serialized values of any arrays stored as meta values. If you expect that possibly an array may be stored as a metavalue, then be prepared to maybe_unserialize.

让小雨知道,这篇文章帮到了你
扫码关注微信公众号zs40086(微搜片)随时随地微信看片,抢先福利电影等你来

热门推荐

如有疑问,请前往问答中心反馈!

反馈