ID; $output = ''; $output .= '

No images.

'; }else{ $output .= cpotheme_gallery_display($images); } //Gallery content $output .= ''; $output .= ' '.__('Add Media', 'cpotheme').''; $output .= ' '.__('Refresh', 'cpotheme').''; $output .= '

'; echo $output; } function cpotheme_gallery_images($post_id){ $args = array( 'post_type' => 'attachment', 'post_status' => 'inherit', 'post_parent' => $post_id, 'exclude' => get_post_thumbnail_id($post_id), 'post_mime_type' => 'image', 'posts_per_page' => -1, 'order' => 'ASC', 'orderby' => 'menu_order'); $images = get_posts($args); return $images; } function cpotheme_gallery_display($imagelist){ $gallery = ''; return $gallery; } //Refresh the metabox function cpotheme_gallery_refresh_metabox(){ $parent = $_POST['parent']; $loop = cpotheme_gallery_images($parent); $images = cpotheme_gallery_display($loop); $ret = array(); if(!empty($parent)){ $ret['success'] = true; $ret['gallery'] = $images; }else{ $ret['success'] = false; } echo json_encode($ret); die(); } //Remove single image function cpotheme_gallery_remove(){ // content from AJAX post $image_id = $_POST['image_id']; $parent = $_POST['parent']; // no image ID came through, so bail if(empty($image_id)){ $ret['success'] = false; echo json_encode($ret); die(); } //Remove attachment - Does not actually delete the file $image_data = array(); $image_data['ID'] = $image_id; $image_data['post_parent'] = 0; $update = wp_update_post($image_data); // AJAX return array $ret = array(); if($update !== 0){ // loop to refresh the gallery $loop = cpotheme_gallery_images($parent); $images = cpotheme_gallery_display($loop); // return values $ret['success'] = true; $ret['gallery'] = $images; }else{ // failure return. can probably make more verbose $ret['success'] = false; } echo json_encode($ret); die(); }