Advertisement
chrishajer

Add meta values to post attachments

Aug 10th, 2012
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.93 KB | None | 0 0
  1. <?php
  2. // http://www.gravityhelp.com/forums/topic/attachment-fields-to-edit
  3. // change 122 to your form ID
  4. add_action('gform_after_submission_122', 'add_attachment_meta', 10, 2);
  5. function add_attachment_meta($entry, $form) {
  6.  
  7.         // Get all images which are attached to this post
  8.         $all_images = get_posts( array(
  9.                 'post_type'      => 'attachment',
  10.                 'post_mime_type' => 'image',
  11.                 'numberposts'    => -1,
  12.                 'post_parent'    => $entry['post_id'] )
  13.         );
  14.  
  15.         // Grab the photographer URL and NAME from the submitted entry
  16.         $ent_name = $entry[32];
  17.         $ent_url  = $entry[33];
  18.  
  19.         // Loop through all image attachments
  20.         foreach ( $all_images as $image ) {
  21.                 update_post_meta($image->ID, 'ent_photographer_name', $ent_name);
  22.                 update_post_meta($image->ID, 'ent_photographer_url',  $ent_url );
  23.         }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement