'', 'order' => 'DESC', 'orderby' => 'date', 'select' => 'all', 'show' => 6, 'max_width' => 77, 'cats' => array(), ); /* Widget setup */ function __construct() { /* Widget settings. */ $widget_ops = array( 'description' => _x( 'Photos', 'widget', 'the7mk2' ) ); /* Create the widget. */ parent::__construct( 'presscore-photos', DT_WIDGET_PREFIX . _x( 'Photos', 'widget', 'the7mk2' ), $widget_ops ); } /* Display the widget */ function widget( $args, $instance ) { static $number = 0; $number++; extract( $args ); $instance = wp_parse_args( (array) $instance, self::$widget_defaults ); /* Our variables from the widget settings. */ $title = apply_filters( 'widget_title', $instance['title'] ); // get albums from selected categories $args = array( 'no_found_rows' => 1, 'posts_per_page' => -1, 'post_type' => 'dt_gallery', 'post_status' => 'publish', 'tax_query' => array( array( 'taxonomy' => 'dt_gallery_category', 'field' => 'term_id', 'terms' => $instance['cats'] ) ), ); switch( $instance['select'] ) { case 'only': $args['tax_query'][0]['operator'] = 'IN'; break; case 'except': $args['tax_query'][0]['operator'] = 'NOT IN'; break; default: unset( $args['tax_query'] ); } $p_query = new WP_Query( $args ); $attachments_ids_array = array(); // get attachments id if ( $p_query->have_posts() ) { foreach( $p_query->posts as $album ) { // get saved data, hope it's array $attachments = get_post_meta( $album->ID, '_dt_album_media_items', true ); if ( !$attachments ) continue; $attachments_ids_array = array_merge( $attachments_ids_array, (array) $attachments ); } } $attachments_ids_array = array_unique($attachments_ids_array); $a_query = false; if ( $attachments_ids_array ) { if ( 'menu_order' == $instance['orderby'] ) { $instance['orderby'] = 'post__in'; if ( 'DESC' == $instance['order'] ) { krsort($attachments_ids_array); $attachments_ids_array = array_values($attachments_ids_array); } } $a_query = new WP_Query( array( 'posts_per_page' => $instance['show'], 'no_found_rows' => 1, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'post_status' => 'inherit', 'post__in' => $attachments_ids_array, 'order' => $instance['order'], 'orderby' => $instance['orderby'], ) ); } echo $before_widget . "\n"; // title if ( $title ) echo $before_title . $title . $after_title . "\n"; if ( $a_query && $a_query->have_posts() ) { $share_buttons = presscore_get_share_buttons_for_prettyphoto( 'photo' ); echo '