Skip Navigation

[Resolved] Featured image is uploaded but not attached to posts created using CRED form

This support ticket is created 7 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 4 replies, has 2 voices.

Last updated by jonE-2 7 years, 7 months ago.

Assisted by: Shane.

Author
Posts
#434689

I have two CRED forms. One for adding a CPT and the other for editing the CPT. I have a field for the featured image to be uploaded. I can upload the featured image in the CRED form; however, it does not attach to the CPT. I verified the image was uploaded in the Media Library.

The Toolset errata states this is a known issue: https://toolset.com/errata/featured-image-uploaded-not-attached-posts-created-using-cred-form/

I have applied the hotfix provided and yet it still does not work.

This was working prior to the CRED update. I need this to work since this is a critical component of the website I am working on. We were planning to launch on Monday and now it has been delayed. Please help as soon as possible.

#434707

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Jon,

Thank you for contacting our support forum.

What you can do is to try our workaround here.
Add the following to your functions.php file

/**
 * Custom code to force add thumbnail meta
 * to add announcement CRED form post
 */
function force_thumbnail( $post_id, $form_data ) {
 
    if ( $form_data['id'] == 1564 && !empty( $_POST['_featured_image'] ) ) {
 
        $args = array(
            'numberposts'   => 1,
            'post_type'     => 'attachment',
            'post_parent'   => $post_id
        );
        $thumb = get_posts( $args );
 
        $meta_update = add_post_meta( $post_id, "_thumbnail_id", $thumb[0]->ID, true );
 
    }
}
add_action( 'cred_submit_complete', 'force_thumbnail', 10, 2 );

Next step is to change the 1564 to the ID of your Cred form.

Please let me know if this helps.
Thanks,
Shane

#434712

Thanks for the update I will try tomorrow and report back.

#435285

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Jon,

Could you update me on the status 🙂

Thanks,
Shane

#435378

Shane,
Thank you for the code snippet. Coupled with the hotfix files, I was able to get the featured image to attach. When CRED 1.8 is updated, will I need to remove the code snippet?

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.