“Function Reference/get post custom values”的版本间的差异

来自WordPress中文文档
跳转至: 导航搜索
 
(1个修订)
(没有差异)

2009年3月14日 (六) 09:23的版本

Description

This function is useful if you wish to access a custom field that is not unique, ie. has more than 1 value associated with it. Otherwise, you might wish to look at get_post_meta()

Returns an array containing all the values of the custom fields with a particular key (tt$key/tt) of a post with ID tt$post_id/tt (defaults to the current post if unspecified).

Returns nothing if no such key exists, or none is entered.

See also get_post_custom() and get_post_custom_keys().

Usage

%%% ?php get_post_custom_values($key, $post_id); ? %%%

Examples

Default Usage

Let's assume the current post has 3 values associated with the (custom) field ttmy_key/tt.

You could show them through: pre?php

 $mykey_values = get_post_custom_values('my_key');
 foreach ( $mykey_values as $key = $value ) {
   echo $key  = $value ('my_key')br /; 
 }

?/pre

0 = First value ('my_key')
1 = Second value ('my_key')
2 = Third value ('my_key')

Parameters

tt$key/tt
(string) (required) The key whose values you want returned.
Default: Nonenoinclude

div class=template-description style=padding: 0 1.5em; border: 1px solid #eeeeee; background-color: #f9f9f9

Notes

This template is for standardizing how parameters look in the Function Reference and in Template Tags. Here is an example of this template being called: prenowiki检查到模板循环:模板:Parameter/nowiki/pre 检查到模板循环:模板:Parameter

The usage of this template is below: prenowiki检查到模板循环:模板:Parameter/nowiki/pre Let's take a closer look at the parameters..

name
The name of the parameter.
datatype
The datatype that should be given for this parameter when called.
  • string
  • integer
  • boolean
  • mixed
description
A short description of the parameter.
importance
Set this parameter to optional if the parameter is optional. Otherwise, do not declare this parameter—it defaults to required.
  • required
  • optional
default
If this parameter is optional, ttdefault/tt is the value that will be used if the parameter is not declared.

wordpress.org.cn /div /noinclude

tt$post_id/tt
(integer) (optional) The post ID whose custom fields will be retrieved.
Default: Current postnoinclude

div class=template-description style=padding: 0 1.5em; border: 1px solid #eeeeee; background-color: #f9f9f9

Notes

This template is for standardizing how parameters look in the Function Reference and in Template Tags. Here is an example of this template being called: prenowiki检查到模板循环:模板:Parameter/nowiki/pre 检查到模板循环:模板:Parameter

The usage of this template is below: prenowiki检查到模板循环:模板:Parameter/nowiki/pre Let's take a closer look at the parameters..

name
The name of the parameter.
datatype
The datatype that should be given for this parameter when called.
  • string
  • integer
  • boolean
  • mixed
description
A short description of the parameter.
importance
Set this parameter to optional if the parameter is optional. Otherwise, do not declare this parameter—it defaults to required.
  • required
  • optional
default
If this parameter is optional, ttdefault/tt is the value that will be used if the parameter is not declared.

wordpress.org.cn /div /noinclude

Related

add_post_meta(), delete_post_meta(), get_post_meta(), update_post_meta(), get_post_custom(), get_post_custom_keys()