好的,下面是应该实现这个技巧的函数:
function modify_events_to_use_new_field() {
$events = get_posts( array(
\'post_type\' => \'event\',
\'post_status\' => \'any\',
\'posts_per_page\' => -1
) );
foreach ( $events as $event ) {
if ( preg_match(\'@^(.*) - ([^-]*)$@\', $event->post_title, $matches) ) {
// you\'ll have to modify the POST_META_KEY to the real name of your custom field
update_post_meta( $event->ID, \'<POST_META_KEY>\', date(\'Ymd\', strtotime($matches[2]) ) );
}
}
}
现在,您必须更改其中自定义字段的名称并运行该函数。