我正在将wordpress自定义字段转换为wp数据库中的单个array.我能做到,但我有重复的条目.我只需要一个.请 bootstrap 我.谢谢
我的代码:
add_action( 'init', function() {
if ( 'migrate' !== filter_input( INPUT_GET, 'action' ) ) {
return;
}
$query = new WP_Query( [
'posts_per_page' => -1,
'post_type' => 'post',
'post_status' => 'any',
] );
if ( ! $query->have_posts() ) {
return;
}
while ( $query->have_posts() ) {
$query->the_post();
$field_id_1 = 'gallery';
$field_value_1 = get_post_meta( get_the_ID(), $field_id_1, false );
update_post_meta( get_the_ID(), $field_id_1, $field_value_1);
}
} );