WP_Query
选择文章而不是元值,这是您无法获得值的方式。您可以使用返回的post ID获取如下值:
$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);
}
它将获取上次发布的帖子的元值,该帖子有一个名为
picture_upload_1
您可以做的另一件事是自己创建一个查询,类似于:
global $wpdb;
$value = $wpdb->get_var( $wpdb->prepare("SELECT meta_value FROM $wpdb->postmeta WHERE meta_key = %s LIMIT 1" , $meta_key) );