Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

im using gravity fields + custom post types Url>iD WordPress

  • SOLVED

im using gravity fields + custom post types to create my custom posts...my troble is when im using image uploaded fields GF writes the url on my data base :

_simple_fields_fieldGroupID_6_fieldID_6_numInSet_0 http://www.toppromomkt.com/wp-content/uploads/gravity_forms/2-f514248af81d6111fa685430cc78a2dc/2015/...


and my costum posts wants to read an ID ...i think i need some kind of filter on my funcions file and maybe make the file go to the wordpress galery in dont know ...can some one help m?

Answers (3)

2015-11-09

Rempty answers:

take a look to this post
https://joshuadnelson.com/connect-gravity-forms-file-upload-to-acf-gallery-field/


aladdinl comments:

hi rempty, i tried the code , but nothing happend , on the database everythings the same...

i changed the $gf_images_field_id = 13; // the upload field id to my GF ulpload field ID and


$acf_field_id = '_simple_fields_fieldGroupID_5_fieldID_2_numInSet_0'; // the acf gallery field id

to my simple field image id (as is in the database)


aladdinl comments:

not even my images are going to the media folder...


Rempty comments:

Dont forget check

$gravity_form_id = 1; //with the correct ID



aladdinl comments:

it was missing :/ but same result :/


aladdinl comments:

i also have a few image acf and i tested with that but no joy


aladdinl comments:

i also have a few image acf and i tested with that but no joy


aladdinl comments:

Just 2 be correct:

$gravity_form_id = 2; ->> i get it from the form it has the id on it

$gf_images_field_id = 13; ->> i get it from the field on the form it has the id on it

$acf_field_id = 'field_5640d510647fd'; ->> i used the firebug to test agaist the field on the upload backoffice field (on the post)

right ?


aladdinl comments:

my debug says

Notice: Use of undefined constant ‘post - assumed '‘post' in /home/arquitek/public_html/toppromomkt.com/wp-content/themes/toppromo/functions.php on line 149

Notice: Use of undefined constant thumbnails’ - assumed 'thumbnails’' in /home/arquitek/public_html/toppromomkt.com/wp-content/themes/toppromo/functions.php on line 149

Notice: Undefined variable: name in /home/arquitek/public_html/toppromomkt.com/wp-content/themes/toppromo/functions.php on line 155

Notice: Undefined variable: width in /home/arquitek/public_html/toppromomkt.com/wp-content/themes/toppromo/functions.php on line 155

Notice: Undefined variable: height in /home/arquitek/public_html/toppromomkt.com/wp-content/themes/toppromo/functions.php on line 155

Notice: Undefined variable: cropBoolean in /home/arquitek/public_html/toppromomkt.com/wp-content/themes/toppromo/functions.php on line 155


Rempty comments:

what type of field are u using? Advanced Field-> Field upload, or Post Fields->Post image


aladdinl comments:

hy rempty im using Post Fields / Advanced Field set to file upload


Rempty comments:

I am using "file upload from advanced Fields", you need a <strong>"post_id"</strong>, i added a custom meta called imageid where save the attachment id. You can add similar code to Kyle answer, just use $id instead of $gallery.

$gravity_form_id = 1; // gravity form id, or replace {$gravity_form_id} below with this number
add_filter( "gform_after_submission_{$gravity_form_id}", 'jdn_set_post_acf_gallery_field', 10, 2 );
function jdn_set_post_acf_gallery_field( $entry, $form ) {

$gf_images_field_id = 2; // the upload field id

$post_id=179;//Set the post ID

// Clean up images upload and create array for gallery field
if( isset( $entry[ $gf_images_field_id ] ) ) {
$images=array($entry[ $gf_images_field_id ]);
if( !empty( $images ) && is_array( $images ) ) {
//$gallery = array();
foreach( $images as $key => $value ) {
if( function_exists( 'jdn_create_image_id' ) )
$image_id = jdn_create_image_id( $value, $post_id );

if( $image_id ) {
$gallery = $image_id;
}
}
}

}
//Asign the image id to a Custom Field called(imageid)
if( ! empty( $gallery ) ) {
update_post_meta($post_id,'imageid',$gallery);
}
}

/**
* Create the image attachment and return the new media upload id.
*
* @since 1.0.0
* @see http://codex.wordpress.org/Function_Reference/wp_insert_attachment#Example
*/
function jdn_create_image_id( $image_url, $parent_post_id = null ) {

if( !isset( $image_url ) )
return false;
global $_wp_additional_image_sizes;
$wp_upload_dir = wp_upload_dir();
$path = parse_url( $image_url, PHP_URL_PATH );
$file_base_name = basename( $image_url );
$uploaded_file_path = ABSPATH . $path;
$filetype = wp_check_filetype( $file_base_name, null );
if( !empty( $filetype ) && is_array( $filetype ) ) {
$post_title = preg_replace( '/\.[^.]+$/', '', $file_base_name );
$attachment = array(
'guid' => $wp_upload_dir['url'] . '/' . basename( $uploaded_file_path ),
'post_mime_type' => $filetype['type'],
'post_title' => esc_attr( $post_title ),
'post_content' => '',
'post_status' => 'inherit'
);

if( !is_null( $parent_post_id ) )
$attachment['post_parent'] = $parent_post_id;
foreach( get_intermediate_image_sizes() as $s ) {
$sizes[$s] = array( 'width' => '', 'height' => '', 'crop' => true );
if( in_array( $s, array( 'thumbnail', 'medium', 'large' ) ) ) {
$sizes[$s]['width'] = get_option( "{$s}_size_w" );
$sizes[$s]['height'] = get_option( "{$s}_size_h" );
$sizes[$s]['crop'] = get_option( "{$s}_crop" );

}
if( isset( $_wp_additional_image_sizes[ $s ] ) ) {
$sizes[ $s ] = array(
'width' => $_wp_additional_image_sizes[ $s ]['width'],
'height' => $_wp_additional_image_sizes[ $s ]['height'],
'crop' => $_wp_additional_image_sizes[ $s ]['crop'],
);
}

}
$sizes = apply_filters( 'intermediate_image_sizes_advanced', $sizes );
foreach( $sizes as $size => $size_data ) {
$resized = image_make_intermediate_size( $uploaded_file_path, $size_data['width'], $size_data['height'], $size_data['crop'] );
if ( $resized )
$attachment['sizes'][$size] = $resized;
}
$attach_id = wp_insert_attachment( $attachment, $uploaded_file_path );
if( !is_wp_error( $attach_id ) ) {
if( file_exists( ABSPATH . 'wp-admin/includes/image.php') && file_exists( ABSPATH . 'wp-admin/includes/media.php') ) {
require_once( ABSPATH . 'wp-admin/includes/image.php' );
require_once( ABSPATH . 'wp-admin/includes/media.php' );
$attach_data = wp_generate_attachment_metadata( $attach_id, $uploaded_file_path );
wp_update_attachment_metadata( $attach_id, $attach_data );
}
}
return $attach_id;
} else {
return false;
}
}



aladdinl comments:

hi rempty ,
"$post_id=179;//Set the post ID " Im not sure what post is to set ! ... my GF gerates my custom posts after submition...





Rempty comments:

Do you have a function to create the custom post after GF submit, or you are using Post Image fields from Post Fields that automatically create a post draft?


aladdinl comments:

im using Gravity Forms + Custom Post Types plugin that creates my custom post (see image) ...but ur code didnt work ...i cant seea any change :(