Home › Forums › General Issues › Setting the post Featured Image based on (PDF) File upload field thumbnail › Reply To: Setting the post Featured Image based on (PDF) File upload field thumbnail
Hi Damiane,
i already did exchange every “publication” with “downloadcenter”, wich is the name of my category, but had file URL as type. Now i changed it to “File Array”, but still nothing happens:
I open a post with category “downloadcenter”, delete the attached file and assign a new file (PDF) and publish it. Now there should be a featured image, I guess – but there isn’t.
Here’s my code:
function set_downloadcenter_post_thumbnail($post_id) {
if(has_category('downloadcenter')) {
$downloadcenter = get_field('downloadcenter', $post_id);
$attachment_id = $downloadcenter['ID'];
update_post_meta($post_id, '_thumbnail_id', $downloadcenter_id);
}
}
add_action('save_post', 'set_downloadcenter_post_thumbnail');
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.