Support

Account

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');