我有成千上万的帖子,每个帖子都包含精选图片。由于某些原因,我需要创建一个Featured_image自定义字段,其中包含特色图片网址。
是否有可能现在制作,或者唯一的方法是在发布之前创建它?
您可以为该帖子类型设置自定义字段,然后可以使用循环更新所有帖子的meta字段并设置功能图片。如下所示
$loop = new WP_Query( array(
'post_type' => 'Property',
'posts_per_page' => -1
)
);
while ( $loop->have_posts() ) : $loop->the_post();
$imageurl = get_the_post_thumbnail_url(get_the_ID(),'full');
update_post_meta( get_the_ID(), 'custom_featured_image', $imageurl );
endwhile; wp_reset_query();