如何在所有包含该图像的现有帖子上添加Featured_image字段

问题描述 投票:0回答:1

我有成千上万的帖子,每个帖子都包含精选图片。由于某些原因,我需要创建一个Featured_image自定义字段,其中包含特色图片网址。

是否有可能现在制作,或者唯一的方法是在发布之前创建它?

php wordpress custom-fields
1个回答
0
投票

您可以为该帖子类型设置自定义字段,然后可以使用循环更新所有帖子的met​​a字段并设置功能图片。如下所示

$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();
© www.soinside.com 2019 - 2024. All rights reserved.