Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

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;
share|improve this answer
    
Thanks for your replay I had tried that but it's give the same Output –  wasim kazi Apr 15 '13 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 Apr 15 '13 at 13:38
    
it's also not working. Now it show blank array. array(0) { } –  wasim kazi Apr 15 '13 at 13:54
1  
Then is must be a another problem, if the array is empty, it's empty. –  Wyck Apr 15 '13 at 14:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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