Hi Tim,
I'm afraid, I couldn't find any information related to any recent changes related to the handling of image upload for generic fields or any previous support thread where users were able to achieve the same for the non-logged-in visitors.
However, I was able to make this work through a workaround.
You can register a new image type user field with slug "user-image" and instead of using an image type generic field include this field in your registration form.
( ref: https://toolset.com/documentation/user-guides/custom-content/user-fields/ )
When the form will be submitted, the image's URL will be saved in this user field, which can be then fetched through the code and set as a value in the custom field for the post, like other fields.
( and once it has fulfilled its purpose, that value can be removed from the user's field too )
The updated code will look like this:
add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data)
{
if ($form_data['id']==2172)
{
// Create post object
$new_post_id = wp_insert_post( array(
'post_title' => $_POST['directory-listing-title'],
'post_content' => '',
'post_status' => 'publish',
'post_author' => $post_ID,
'post_type' => 'directory-listing'
) );
update_post_meta($new_post_id, 'wpcf-phone-number', $_POST['directory-listing-phone']);
update_post_meta($new_post_id, 'wpcf-email-address', $_POST['directory-listing-email']);
update_post_meta($new_post_id, 'wpcf-district', $_POST['select-district']);
update_post_meta($new_post_id, 'wpcf-website', $_POST['directory-website']);
update_post_meta($new_post_id, 'wpcf-facebook', $_POST['facebook']);
update_post_meta($new_post_id, 'wpcf-place-description', $_POST['place-description']);
update_post_meta($new_post_id, 'wpcf-coupon-details', $_POST['coupon-details']);
update_post_meta($new_post_id, 'wpcf-user-category', $_POST['listing-category']);
update_post_meta($new_post_id, 'wpcf-user-added-sub-category', $_POST['listing-sub-category']);
update_post_meta($new_post_id, 'wpcf-new-business-listing', $_POST['new-business-listing']);
update_post_meta($new_post_id, 'wpcf-location-address', $_POST['location-address']);
wp_set_object_terms( $new_post_id, $_POST['new-business-listing'], 'new-business-listing', true );
// get image URL value from the user
$user_image = get_user_meta( $post_id, 'wpcf-user-image', true );
// if image URL exists
if (!empty($user_image)) {
// set the image URL as new post's custom field value
update_post_meta($new_post_id, 'wpcf-location-image', $user_image);
// delete the image URL from user's custom fiedl
delete_user_meta($post_id, 'wpcf-user-image');
}
}
}
Note: The variable "$post_ID" holds the newly added user's ID while "$new_post_id" holds the newly added post's ID.
This should do the trick.
regards,
Waqar