我在一个名为clothing
的自定义帖子类型中有数千个帖子,其中有一个名为wpcf-translation
的自定义字段
我需要在每个帖子的wpcf-translation
自定义字段中插入一个字符串。
但我在互联网上找不到任何东西。所以我的问题是,是否有一个SQL查询可用于将字符串插入到每个帖子的自定义字段中wpcf-translation
自定义帖子类型clothing
?
谢谢
根据您的评论:我认为该字段没有序列化。 ,以下应该完成工作
$args = array(
'post_type' => 'clothing',
'posts_per_page' => -1,
);
$query = new WP_Query( $args );
while( $query->have_posts() ) : if( $query->have_posts() ) : $query->the_post();
update_post_meta($post->ID, 'wpcf-translation' , 'your string here');
else :
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
endif;
endwhile;
wp_reset_postdata();
确保您有备份,以防出现问题。动态创建的代码,因此可能需要一些微调。