wordpress获取自定义字段值函数:get_post_custom()


【描述】
同get_post_meta()一样,用于返回文章的自定义字段值得一个函数,只不过get_post_custom()函数使用起来更简单,如果在循环中使用你甚至不需要设置任何参数。

【用法】

  1. <?php get_post_custom($post_id); ?>

【参数】
$post_id

(整数)(可选)将要检索的自定义字段的文章编号。

默认值:Current post

【示例】

  1. if (have_posts()) :
  2. while (have_posts()) : the_post();
  3. var_dump(get_post_custom());
  4. endwhile;
  5. endif;

输出的结果如下:(如果如下字段有设置的话)

  1. array(4) {
  2. ["_edit_last"]=>
  3. array(1) {
  4. [0]=>
  5. string(1) 1
  6. }
  7. ["_edit_lock"]=>
  8. array(1) {
  9. [0]=>
  10. string(12) 1342451729:1
  11. }
  12. ["_thumbnail_id"]=>
  13. array(1) {
  14. [0]=>
  15. string(3) 228
  16. }
  17. ["xzmeta"]=>
  18. array(2) {
  19. [0]=>
  20. string(3) xz1
  21. [1]=>
  22. string(3) xz2
  23. }
  24. }

【源代码】

  1. get_post_custom() 位于 wp-includes/post.php