0

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.

1 Answer 1

2

You have the parameter of get_post_meta set to true which returns single result, set it to false or remove it completely.

 $dump_array = get_post_meta(get_the_id(), '_as_roomname')
 //check whats in the array
 var_dump($dump_array);

// or loop for output
foreach( $dump_array as $dump )
echo $dump;
4
  • Thanks for your replay I had tried that but it's give the same Output
    – wasim kazi
    Commented Apr 15, 2013 at 13:35
  • Setting it to false or empty returns an array, so you have to loop over it for output most likely using foreach, I edited my answer.
    – Wyck
    Commented Apr 15, 2013 at 13:38
  • it's also not working. Now it show blank array. array(0) { }
    – wasim kazi
    Commented Apr 15, 2013 at 13:54
  • 1
    Then is must be a another problem, if the array is empty, it's empty.
    – Wyck
    Commented Apr 15, 2013 at 14:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.