I found part of the problem – my child theme was not active, so the code did not work. Sorry for that …
After activating there is still no thumbnail, but now there is a “replace featured image” button in my post (see screenshot), so something happend to the post. But it does not to seem a vaild image file.
Hi @damianemuller,
thank you for looking over my code. I could have realized this myself, sorry.
But: Also with the updated line nothing happens. I did change the attachment of a post, updated the post – but there still is no featured image.
@hube2 Thank you for making clear, good to know.
The ACF field Label is “Download”, and the field Name is “downloadcenter”.
The category name is “Downloadcenter” and the category slug is “downloadcenter”.
Site health is good, PHP version is 7.4.5
If I post credentials and mark them as “private”, only you will see them, correct?
Hi Damiane, I can’t see your reply as it has been marked as private.
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');
Hi Damiane,
I do need exactly the same, great help. But is your code still working with WP 5.9.2?
I tried it, but nothing happens.
Best regards
Uli
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.