Guest User

Untitled

a guest
Jul 18th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. add_action('pmxi_saved_post', 'update_gallery_ids', 10, 3);
  2. function update_gallery_ids($id) {
  3.  
  4. $attached_images = get_attached_media( 'image', $id );
  5.  
  6. // Prepare images into array
  7. $arr = array();
  8. foreach($attached_images as $image)
  9. array_push($arr, $image->ID);
  10.  
  11. // Prepare shortcode
  12. $string = '<p>[gallery ids="'. implode(", ",$arr) . '"]</p>';
  13.  
  14. // Prepare post for updating
  15. $content_post = get_post($id);
  16. $content = $content_post->post_content;
  17. $my_post = array();
  18. $my_post['ID'] = $id;
  19. $my_post['post_content'] = $content . $string;
  20.  
  21. // Save post
  22. wp_update_post( $my_post );
  23.  
  24. }
Add Comment
Please, Sign In to add comment