Hi,
I'm building a website for a client and one of the requirements is to allow the user to upload posts with images.
I've tried the following code(https://toolset.com/forums/topic/use-first-uploaded-image-as-featured-image/), but it's not working.
My form id (5645) and field (more-pic) are inserted, but when I run it trough, I get error and it cannot be activated.
add_action('cred_save_data', 'set_image_as_featured',10,2);
function set_image_as_featured($post_id, $form_data)
{// if a specific form
if ($form_data['id']==5645)
{ if (isset($_POST['wpcf-more-pic']))
{ $image = $_POST['wpcf-more-pic'][0];
// Save the first image as featured image
set_post_thumbnail($post_id,attachment_url_to_postid($image)); } }}
Website: hidden link
Currently I'm using the standard featured image field in addition to the repeating images, but it's not user friendly to ask to upload several images trough different fields, so the feature image of the post shows.
Edit: It appears I've deleted the php head by mistake. It's working now
Edit: It appears I've deleted the php head by mistake. It's working now