您需要使用WP_Query 获取与您的查询匹配的帖子。
并且在WP_Query
您需要使用以下各项:
\'meta_query\' => array(
\'meta_key\' => \'date_started\', // change it to your custom field meta_key
\'type\' => \'DATE\', // You can also try changing it to TIME or DATETIME if it doesn\'t work
\'meta_value\' => \'2017-05-23\', // Replace with your preferred value
\'meta_compare\' => \'=\',
),
完整的代码如下所示:
<?php
$post_query = new WP_Query(
array(
\'post_type\' => \'post\',
\'posts_per_page\' => 1,
\'meta_query\' => array(
\'meta_key\' => \'date_started\', // change it to your custom field meta_key
\'type\' => \'DATE\', // You can also try changing it to TIME or DATETIME if it doesn\'t work
\'meta_value\' => \'2017-05-23\', // Replace with your preferred value
\'meta_compare\' => \'=\',
),
)
);
if($post_query->have_posts()) : while($post_query->have_posts()) : $post_query->the_post();
the_title(); // Print the title of found post
endwhile;
endif;
wp_reset_postdata();
?>