0

我发了一篇自定义帖子,其中有一个自定义字段调用_as_roomname

我创建了总共 5 个自定义帖子,我想检索它的所有名称,但我只得到第一个值。

function postlogo(){
global $post;
$counting = 1;
$count = 1;
$args = array( 'post_type' => 'casino', 'posts_per_page' => 5 );
$rPosts = new WP_Query($args);

while ($rPosts->have_posts()) : $rPosts->the_post();?>
<h1><?php echo get_post_meta(get_the_id(), '_as_roomname', true);?> Review </h1><?php
$count = $count + 1;    
endwhile;
} 

输出

Casino.com Review
Casino.com Review
Casino.com Review
Casino.com Review
Casino.com Review

我想要所有帖子中的这个唯一名称,但它只给我第一个值。我怎么会得到我不知道的。

4

1 回答 1

2

You are passing current post id (get_the_id()) in get_post_meta function which seems incorrect. Pass the id of the post you are getting in loop.

 get_post_meta($rPosts->post->ID , '_as_roomname', true);
于 2013-04-15T13:19:30.797 回答