WordPress自定义字段图像未插入到数组中

时间:2014-10-14 10:55:00

标签: php wordpress twitter-bootstrap

我正在使用Wordpress使用Bootstrap创建动态图库。我创建了一个新的自定义字段,然后将其设置为' images'然后将其分配给我的帖子类型。它然后显示在我的帖子中,我将我的图像上传到字段中,然后尝试将所有附件放入一个数组,然后我将循环显示它们。

$args = array(
'post-type' => 'attachment',
'numberposts' => -1,
'post_status' => 'any',
'post_parent' => $post->ID,
'exclude' => get_post_thumbnail_id()
);

$attachments = get_posts($args);

执行此操作并执行带附件的var转储后,它表示数组中没有任何内容

1 个答案:

答案 0 :(得分:1)

要在帖子中显示自定义字段值,您必须在帖子显示循环中使用<?php echo get_post_meta($post->ID,'custom-field-name',true) ?>