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 want to get all the post ids when the post meta includes a key of "project_id". This function get the job down, but need refine:

function get_all_ids(){
global $wpdb, $post;
$meta_key1 = 'project_id';
$postids = $wpdb->get_col( $wpdb->prepare( "
    SELECT key1.post_id
    FROM $wpdb->postmeta key1
    WHERE key1.meta_key = %s",$meta_key1 ) );
return $postids;
}

This returns arrays of (0 =>1), ( 1 =>3 ), (2 =>5) In the later step, I will need to get the ids like this:

$this->results = $projects->get_all_ids();

This requires the ids are not arrays. How can I get all the ids without array?

share|improve this question
    
In what format do you expect to have the list of ids? –  MZAweb May 29 '11 at 6:49
    
I'm not sure. I am trying to make a loop for an object which attached to each post. If has ids, the loop will start. When there is an id, I can get data from a class. –  Jenny May 29 '11 at 6:58
    
If there is a loop that process those ids then array is the best format, but if you can show us that loop then we will actually know in what format does the loop expects the result. –  Hameedullah Khan May 29 '11 at 7:12
    
the loop is too long, this comment box not allow. –  Jenny May 29 '11 at 7:53
    
ok, find a way-- this is the original loop: github.com/kunalb/EventPress/blob/master/views/kb-loop.php , I will make an extends of this kb-loop for my object. –  Jenny May 29 '11 at 8:01
show 1 more comment

1 Answer 1

If you need the ids separated by coma you can get them from the array you have:

$listids = implode ( "," , $postids );

In any case, please provide more info or code about what you need

share|improve this answer
    
would you please take a look at the loop I posted in the above comment? –  Jenny May 29 '11 at 22:30
    
I want the formate llike this: 'project id' => 1,'height'=>x,'width'=>y –  Jenny May 29 '11 at 22:44
add comment

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.