Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action('pmxi_saved_post', 'update_gallery_ids', 10, 3);
- function update_gallery_ids($id) {
- $attached_images = get_attached_media( 'image', $id );
- // Prepare images into array
- $arr = array();
- foreach($attached_images as $image)
- array_push($arr, $image->ID);
- // Prepare shortcode
- $string = '<p>[gallery ids="'. implode(", ",$arr) . '"]</p>';
- // Prepare post for updating
- $content_post = get_post($id);
- $content = $content_post->post_content;
- $my_post = array();
- $my_post['ID'] = $id;
- $my_post['post_content'] = $content . $string;
- // Save post
- wp_update_post( $my_post );
- }
Add Comment
Please, Sign In to add comment