从自定义字段返回名称


Echo name from custom field wordpress

我有一个while循环来获取特定类别中的所有帖子,现在我添加了自定义值但问题是它只回显自定义字段的值而不回显名称

我用来输出值的函数是

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    the_meta();
<?php endwhile; endif;?>

现在我已经尝试回显get_post_custom_keys($post->ID);但这只给我输出"array"

我也尝试了foreach循环,但它只给了我最后一个帖子的名字

$meta_key_used = get_post_custom_keys($post->ID); 
foreach ($meta_key_used as $meta_key) {
echo $meta_key;

关于如何打印自定义字段的名称有什么想法吗?

如果你有所有你想调用的post id,那么你可以这样做…

$post_ids = array(1, 2, 3, 4, 5);  // for example
foreach ($post_ids as $post_id)
{
  $meta_key_used = get_post_custom_keys($post_id); 
  echo "Custom key names for post " . $post_id . "...<br />";
  foreach ($meta_key_used as $array_key => $meta_key_name)
  {
    $namet = trim($meta_key_name);
    if ('_' == $namet{0})    // ignore wp internal keys
      continue; 
    echo $array_key . " => " . $meta_key_name . "<br />";
  }
}

不包括任何以下划线开头的Wordpress内部键