Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

post images #11

Open
saltnpixels opened this issue Nov 20, 2016 · 0 comments
Open

post images #11

saltnpixels opened this issue Nov 20, 2016 · 0 comments

Comments

@saltnpixels
Copy link

saltnpixels commented Nov 20, 2016

Love your plugin.
Just wish i could have more power with the post images. Gravity forms doesnt let you save a post image to a custom field. So made my own way here:

I use pods to make custom fields of type image. The value msut be a media ID.
When i add post image fields in gravity forms I can make them save to the post by grabbing the media_id which is put at the end of the entry value string for post images. Like this:

add_action( 'gform_after_submission', 'add_post_image', 10, 2 );
function add_pot_image( $entry, $form ) {
   
   //it is being saved to a post
   if(isset($entry['post_id']) ){
       $post_id = $entry['post_id'];
    
         foreach($form['fields'] as $field){
         //if its a post image type and is not being saved as featured and the class starts with field_  
         if($field['type'] == 'post_image' && $field['postFeaturedImage'] == '' && strpos($field['cssClass'], 'field_') !== false){
            
            $entry_id = $field['id'];
            //getting the last digits which are the media_id from entry value
            preg_match('/[0-9]*$/', $entry[$entry_id], $value);
            
            //css class must start with field_ this way you can still have other css classes
            preg_match('/field_(\w*)/', $field['cssClass'], $custom_field);
         
            update_post_meta($post_id, $custom_field[1], $value[0]);
           }
         }
        }    
     }

Here if a field has a css class of field_something it will find post meta with key 'something' and add the image.
Now how the heck can I prepopulate this and have it save!! Post images doesnt even let you pre poulate! ugh...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant