This support ticket is created vor 4 Jahre, 2 Monate. 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.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
First, I removed wpcf- prefix from the code.
If I add it in front of the field slug, the pictures don't even show in the gallery custom field in back-end editor (they are uploaded into the media library, though) and neither in woocomerce gallery.
Without the prefix the pictures show in the back-end in my gallery custom fields but not in woocommerce gallery.
I only changed form id and my custom field slug in the provided code..
Thank you for waiting, while I performed some troubleshooting.
I noticed that in your target form "Alternative places form" (ID: 39), the option "Use the WordPress Media Library manager for image, video, audio, or file fields" was not checked.
( screenshot: hidden link )
Here is the slightly updated code snippet, which will work whether that option is turned on or not:
add_action('cred_save_data', 'cred_product_gallery_action',10,2);
function cred_product_gallery_action($post_id, $form_data)
{
global $wpdb;
// if a specific form
if ($form_data['id']==39)
{
if (isset($_POST['wpcf-photo-gallery-alt']))
{
$list_ids = array();
$existing_values = get_post_meta( $post_id, 'wpcf-photo-gallery-alt', false );
foreach($existing_values as $url)
{
$item_id = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid='%s';", $url ));
$list_ids[] = $item_id[0];
}
update_post_meta($post_id, '_product_image_gallery', implode($list_ids,','));
delete_post_meta($post_id, 'wpcf-photo-gallery-alt');
}
}
}
I hope this helps and please let me know how it goes.
Thank you so much, it works great now.
I had to disable media library button because I got some other issues with the featured image but I'll create a new ticket if I can't sort it out by myself.
Thanks again and all the best,
pz
This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.