'abedul-formats', 'description' => __('Use this widget to show some of your formatted posts','abedul'), ); parent::__construct( 'abedul-formats', __('Abedul Formats', 'abedul'), $widget_ops ); } /** * Outputs the content of the widget * * @param array $args * @param array $instance */ public function widget( $args, $instance ) { // outputs the content of the widget $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base ); // Puts the selected post formats in an array that can be used in the query. $terms = array(); foreach ($this->formats as $key => $value) { if ( ! empty( $instance['formats'][$value] ) ) { $value = $instance['formats'][$value]; $terms[]= 'post-format-'.$value; } } // Starts the query work. $is_sticky = get_option( 'sticky_posts' ); $args_query = array( 'posts_per_page' => 30, 'post__not_in' => $is_sticky, 'ignore_sticky_posts' => 1, 'tax_query' => array( array( 'taxonomy' => 'post_format', 'field' => 'slug', 'terms' => $terms, 'operator' => 'IN', ),),); $query = new WP_Query($args_query); if ( $query->have_posts() ): echo $args['before_widget']; echo '
formats as $key => $slug ):?>
/>