哦,天哪。你在做一些奇怪的事情。:)
请这样尝试:
$args = array(
\'posts_per_page\' => -1,
\'post_type\'=> \'match_report\',
);
$query = new WP_Query($args);
if ($query->have_posts()) {
while ($query->have_posts()) {
$query->the_post();
$matchdate = get_post_meta(get_the_ID(), \'report_date\', true);
$new_matchdate = DateTime::createFromFormat(\'d-m-Y\', $matchdate);
update_post_meta(get_the_ID(), \'report_date\', $new_matchdate->format(\'Y-m-d\'));
}
wp_reset_postdata();
}
// EDIT如果您在以面向对象的方式进行操作时遇到问题,请尝试以下过程:
$args = array(
\'posts_per_page\' => -1,
\'post_type\'=> \'match_report\',
);
$query = new WP_Query($args);
if ($query->have_posts()) {
while ($query->have_posts()) {
$query->the_post();
$matchdate = get_post_meta(get_the_ID(), \'report_date\', true);
$new_matchdate = date_create_from_format(\'d-m-Y\', $matchdate);
update_post_meta(get_the_ID(), \'report_date\', date_format($new_matchdate, \'Y-m-d\'));
}
wp_reset_postdata();
}