【描述】
同get_post_meta()一样,用于返回文章的自定义字段值得一个函数,只不过get_post_custom()函数使用起来更简单,如果在循环中使用你甚至不需要设置任何参数。
【用法】
- <?php get_post_custom($post_id); ?>
【参数】
$post_id
(整数)(可选)将要检索的自定义字段的文章编号。
默认值:Current post
【示例】
- if (have_posts()) :
- while (have_posts()) : the_post();
- var_dump(get_post_custom());
- endwhile;
- endif;
输出的结果如下:(如果如下字段有设置的话)
- array(4) {
- ["_edit_last"]=>
- array(1) {
- [0]=>
- string(1) “1″
- }
- ["_edit_lock"]=>
- array(1) {
- [0]=>
- string(12) “1342451729:1″
- }
- ["_thumbnail_id"]=>
- array(1) {
- [0]=>
- string(3) “228″
- }
- ["xzmeta"]=>
- array(2) {
- [0]=>
- string(3) “xz1″
- [1]=>
- string(3) “xz2″
- }
- }
【源代码】
- get_post_custom() 位于 wp-includes/post.php