'mh_custom_posts', 'description' => esc_html__('Custom Posts Widget to display posts based on categories or tags.', 'mh-magazine-lite'), 'customize_selective_refresh' => true ) ); } function widget($args, $instance) { $defaults = array('title' => '', 'category' => 0, 'tags' => '', 'postcount' => 5, 'offset' => 0, 'sticky' => 1); $instance = wp_parse_args($instance, $defaults); $query_args = array(); if (0 !== $instance['category']) { $query_args['cat'] = $instance['category']; } if (!empty($instance['tags'])) { $tag_slugs = explode(',', $instance['tags']); $tag_slugs = array_map('trim', $tag_slugs); $query_args['tag_slug__in'] = $tag_slugs; } if (!empty($instance['postcount'])) { $query_args['posts_per_page'] = $instance['postcount']; } if (0 !== $instance['offset']) { $query_args['offset'] = $instance['offset']; } if (1 === $instance['sticky']) { $query_args['ignore_sticky_posts'] = true; } $widget_loop = new WP_Query($query_args); echo $args['before_widget']; if (!empty($instance['title'])) { echo $args['before_title']; if ($instance['category'] != 0) { echo ''; } echo esc_html(apply_filters('widget_title', $instance['title'])); if ($instance['category'] != 0) { echo ''; } echo $args['after_title']; } ?> 50) { $instance['postcount'] = 50; } else { $instance['postcount'] = absint($new_instance['postcount']); } } if (0 !== absint($new_instance['offset'])) { if (absint($new_instance['offset']) > 50) { $instance['offset'] = 50; } else { $instance['offset'] = absint($new_instance['offset']); } } $instance['sticky'] = (!empty($new_instance['sticky'])) ? 1 : 0; return $instance; } function form($instance) { $defaults = array('title' => '', 'category' => 0, 'tags' => '', 'postcount' => 5, 'offset' => 0, 'sticky' => 1); $instance = wp_parse_args($instance, $defaults); ?>

/>