'adminz_widget_recent_entries', 'description' => __('Your site’s most recent Posts.'), 'customize_selective_refresh' => true, 'show_instance_in_rest' => true, ); parent::__construct('adminz_recent_posts', __('Adminz Recent Posts'), $widget_ops); $this->alt_option_name = 'adminz_widget_recent_entries'; } public function widget($args, $instance) { if (!isset($args['widget_id'])) { $args['widget_id'] = $this->id; } $title = (!empty($instance['title'])) ? $instance['title'] : __('Recent Posts'); $title = apply_filters('widget_title', $title, $instance, $this->id_base); $number = (!empty($instance['number'])) ? absint($instance['number']) : 5; $number = $number ? $number : 5; $show_date = isset($instance['show_date']) ? $instance['show_date'] : false; $show_thumb = isset($instance['show_thumb']) ? $instance['show_thumb'] : false; $post_type = (!empty($instance['post_type'])) ? $instance['post_type'] : 'post'; // Default to 'post' $r = new \WP_Query(apply_filters( 'widget_posts_args', array( 'posts_per_page' => $number, 'post_type' => $post_type, // Use selected post type 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true, ), $instance )); if (!$r->have_posts()) { return; } echo $args['before_widget']; if ($title) { echo $args['before_title'] . $title . $args['after_title']; } $format = current_theme_supports('html5', 'navigation-widgets') ? 'html5' : 'xhtml'; $format = apply_filters('navigation_widgets_format', $format); if ('html5' === $format) { $title = trim(strip_tags($title)); $aria_label = $title ? $title : __('Recent Posts'); echo ''; } echo $args['after_widget']; } public function update($new_instance, $old_instance) { $instance = $old_instance; $instance['title'] = sanitize_text_field($new_instance['title']); $instance['number'] = (int) $new_instance['number']; $instance['show_date'] = isset($new_instance['show_date']) ? (bool) $new_instance['show_date'] : false; $instance['show_thumb'] = isset($new_instance['show_thumb']) ? (bool) $new_instance['show_thumb'] : false; $instance['post_type'] = sanitize_text_field($new_instance['post_type']); // Save selected post type return $instance; } public function form($instance) { $title = isset($instance['title']) ? esc_attr($instance['title']) : ''; $number = isset($instance['number']) ? absint($instance['number']) : 5; $show_date = isset($instance['show_date']) ? (bool) $instance['show_date'] : false; $show_thumb = isset($instance['show_thumb']) ? (bool) $instance['show_thumb'] : false; $post_type = isset($instance['post_type']) ? esc_attr($instance['post_type']) : 'post'; // Default to 'post' ?>

id="get_field_id('show_date'); ?>" name="get_field_name('show_date'); ?>" />

id="get_field_id('show_thumb'); ?>" name="get_field_name('show_thumb'); ?>" />