Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- add_filter( 'rwmb_meta_boxes', 'prefix_attached_images_meta_box' );
- function prefix_attached_images_meta_box( $meta_boxes ) {
- $meta_boxes[] = array(
- 'title' => esc_html__( 'Attached images', 'textdomain' ),
- 'fields' => array(
- array(
- 'type' => 'custom_html',
- 'callback' => 'prefix_get_images',
- ),
- ),
- );
- return $meta_boxes;
- }
- function prefix_get_images() {
- $post_id = false;
- if ( isset( $_GET['post'] ) ) {
- $post_id = intval( $_GET['post'] );
- } elseif ( isset( $_POST['post_ID'] ) ) {
- $post_id = intval( $_POST['post_ID'] );
- }
- if ( ! $post_id ) {
- return '';
- }
- $attachments = get_children( array(
- 'post_parent' => $post_id,
- 'post_type' => 'attachment',
- 'post_mime_type' => 'image',
- 'numberposts' => - 1,
- 'post_status' => 'any',
- ) );
- if ( empty( $attachments ) ) {
- return esc_html__( 'No images attached', 'textdomain' );
- }
- $output = '';
- foreach ( $attachments as $attachment ) {
- $output .= wp_get_attachment_image( $attachment->ID, 'thumbnail' );
- }
- return $output;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement