Reputation: 378
I made one custome post in that there is one custom field call _as_roomname.
I create total 5 custom post and I want to retrive all it's name but I get only first value.
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;
}
Output
Casino.com Review
Casino.com Review
Casino.com Review
Casino.com Review
Casino.com Review
I want this unique name from all post but it give me only first value. How will I get that I don't know.
Upvotes: 0
Views: 828
Reputation: 26421
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);
Upvotes: 2