Support

Account

Home Forums General Issues Set featured image of CPT from existing image Reply To: Set featured image of CPT from existing image

  • get_post_meta() and set_post_thumbnail() always exist. The problem you’d run into is if ACF is not installed and this would work only when you actually updated the post in the admin.

    Would it be possible to do this to every post? Yes, but it’s far more complicated and may not actually work. If there are many posts it could time out before it completes. The other question is “When do you run it?” What will trigger it to run. It’s not something you’d want to do every time a page is loaded or even every time the admin is loaded.

    To do it all at once you’d need to get all the posts, loop through them and get the custom field for each and then update the featured image.

    I don’t really see any easier way to do it. The only thought I have is to somehow hook into WP where it get’s the information for each post, before it actually gets the post and do it then… but that may actually cause an infinite loop.

    You might be able to use the ‘the_post’ hook to create an action that would run on each post when it’s loaded. Check it there and do the update then. But I’m not really sure what you’d need to do with this.