Skip to content
Advertisement

get post meta for all id [closed]

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?

Advertisement

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 );
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement