wordpress get meta value by meta key

WP_Query selects posts and not meta value that is way you are not getting the value.
You can use the returned post ID to get the value something like:

$args = array(
    'post_type' => 'post',
    'post_status' => 'publish',
    'posts_per_page' => 1,
    'meta_key' => 'picture_upload_1'
);
$dbResult = new WP_Query($args);
global $post;
if ($dbResult->have_posts()){
   $dbResult->the_post();
   $value = get_post_meta($post->ID,'picture_upload_1',true);
}

which will get the meta value of the last post published which has a custom field named picture_upload_1

another thing you can do is create a query your self , something like:

 global $wpdb;
 $value = $wpdb->get_var( $wpdb->prepare("SELECT meta_value FROM $wpdb->postmeta WHERE meta_key = %s LIMIT 1" , $meta_key) );

Leave a Comment