|
CRED repeating image fields – gallery. Woo and non-woo
Started by: filipV-3
in: Toolset Professional Support
Quick solution available
Problem: I would like to allow my site users to upload images and create a product image gallery when they create a new Product using CRED. I would rather not show the custom fields in the Product editing screen.
Solution: Create a repeating image custom field and apply that field to the Product post type. Create a CRED form that will create new Products. Auto-generate the form so your custom repeated image input is added. Use the cred_save_data hook to capture the images uploaded with CRED, and determine the image IDs using the post guid and image URLs. Generate a comma-separated list of IDs, and store that list in the _product_image_gallery meta field of the new Product.
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']==69)
{
if (isset($_POST['wpcf-product-gallery-image-cred']))
{
$list_ids = array();
foreach($_POST['wpcf-product-gallery-image-cred'] 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-product-gallery-image-cred');
}
}
}
You may twirl the custom field section closed in the Product editing screen, or you can hide it completely from the admin area using the Screen Options tab in the top right corner of the admin screen.
Relevant Documentation: https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
|
|
2 |
11 |
7 years, 3 months ago
Christian Cox
|
|
I would like to access to a custom field
Started by: oriolc
in: Toolset Professional Support
Quick solution available
Problem: I have a CRED form that creates Post Type A. I have placed this CRED form on Page B. There is a custom field on Page B that I would like to use in my CRED form email notifications. How can I capture the information from the current Page B inside the email notification for Post A?
Solution: Add a generic field to your CRED form. Set the "default" value of this field using the wpv-post-field shortcode, referencing current Page B with the id attribute "$current_page".
[cred_generic_field field="fecha-fin" type="date" class='' urlparam=""]
{
"required":0,
"validate_format":0,
"persist":1,
"default":"[wpv-post-field id='$current_page' name='wpcf-fecha-final']"
}
[/cred_generic_field]
Use the cred_save_data hook to add the value of this generic field to a custom field in Post Type A. Then you can display the value of this custom field in your CRED notifications.
add_action('cred_save_data', 'save_parent_fecha_fin',10,2);
function save_parent_fecha_fin($post_id, $form_data)
{
// if a specific form
if ($form_data['id']==550)
{
if (isset($_POST['fecha-fin']))
{
update_post_meta($post_id, 'wpcf-fecha-fin', $_POST['fecha-fin'], true);
}
Relevant Documentation:
https://toolset.com/documentation/user-guides/cred-shortcodes/#cred_generic_field
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-post-field
|
|
2 |
11 |
7 years, 4 months ago
oriolc
|
|
Using cred_delete_post_link in PHP return
Started by: monicaI
in: Toolset Professional Support
Quick solution available
Problem: I would like to generate a delete post link for a CRED post, but I do not want to echo it onto the page.
Solution: It's not possible at the moment, instead you could use an Edit CRED form and the cred_save_data hook to delete the post.
Relevant Documentation: https://toolset.com/documentation/programmer-reference/cred-api/
|
|
2 |
5 |
7 years, 4 months ago
monicaI
|