-1

I have an SQL SELECT request

select v.id
from wp_posts v
join wp_postmeta pm on (pm.post_id = v.id)
join wp_posts p on (v.post_parent = p.id)
where meta_key ='_price'
and v.post_type = 'product_variation'
and p.id = '1743'

It works well and returns me 2 values, each one in new line:

1744

1745

I'm trying to put this values to php array

$rbp_ids[] = $wpdb->get_var( $wpdb->prepare("
select v.id from wp_posts v
join wp_postmeta pm on (pm.post_id = v.id)
join wp_posts p on (v.post_parent = p.id)
where meta_key ='_price'
and v.post_type = 'product_variation'
and p.id = '1743'"));

And do an echo function

foreach( $rbp_ids as $rbp_id){

echo $rbp_id

}

But this function returns me only one first value from select:

1744

Is it possible to make an array like (1744,1745)?

closed as off-topic by LowlyDBA, joanolo, mustaccio, RDFozz, McNets Jul 2 '17 at 18:01

If this question can be reworded to fit the rules in the help center, please edit the question.

1

Oh...i need to use $wpdb->get_col

  • 1
    Can you provide a little more detail? I assume that the get_var function only returns the first value in the first row fro the result set, while get_col loads all the results from one column into an array? But it's not clear from the context (for that matter, it's not clear that this is an answer to the question rather than a misplaced note that should have been edited into the question). If it is an answer and solves your problem, go ahead and accept it, so we know that for sure. – RDFozz Jun 30 '17 at 17:58

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