'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 '

'.esc_html($title).'

'; ?>
have_posts() ): $query->the_post(); get_template_part( 'template-parts/content', get_post_format() ); endwhile; wp_reset_postdata(); ?>
formats as $key => $value) { $instance['formats'][$value] = !empty($new_instance['formats'][$value]) ? $new_instance['formats'][$value] : 0; } return $instance; } /** * Display the form for this widget on the Widgets page of the Admin area. * * @since Abedul 1.0.4 * * @param array $instance The widget options */ public function form( $instance ) { foreach ($this->formats as $slug) { $formats[$slug] = false; } $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'formats' => $formats )); $title = empty($instance['title'])? '' : esc_attr( $instance['title']); foreach ($this->formats as $key => $slug) { $slug = isset($instance['formats'][$slug]) ? $instance['formats'][$slug] : 0; } ?>

formats as $key => $slug ):?> />