get post meta for all id [closed]

Tags: , ,



I want to get all brands from DB. It should work like get_post_meta( get_the_id(), 'make', true); but without id. It should contain an array with all brands. Which command I should use?

Answer

Try the below query.

global $wpdb;
$make = $wpdb->get_results("SELECT meta_value FROM $wpdb->postmeta WHERE meta_key = 'make' ");

Update

global $wpdb;
$makes = $wpdb->prepare("SELECT meta_value FROM $wpdb->postmeta WHERE meta_key = 'make' ",ARRAY_A);
$makes = $wpdb->get_col( $makes );
$makes = implode( ',', $makes );


Source: stackoverflow