好的,在@jonathan-wold, 我想出了解决问题的办法。在我的初始代码中,我只是替换了$args
部分,因此提到的作者,这就像一个魅力。代码如下:
$args = array(
\'post_type\' => \'events\', // Tell WordPress which post type we want
\'orderby\' => \'meta_value\', // We want to organize the events by date
\'meta_key\' => \'event_start_date\', // Grab the "start date" field created via "More Fields" plugin (stored in YYYY-MM-DD format)
\'order\' => \'ASC\', // ASC is the other option
\'posts_per_page\' => \'1\', // Let\'s show only one / the first event.
\'meta_query\' => array( // WordPress has all the results, now, return only the events after today\'s date
array(
\'key\' => \'event_start_date\', // Check the start date field
\'value\' => date("Y-m-d"), // Set today\'s date (note the similar format)
\'compare\' => \'>=\', // Return the ones greater than or equal to today\'s date
\'type\' => \'DATE\' // Let WordPress know we\'re working with date
)
)
);