esc_html__('This Widget show Random Category Posts.', 'allrounder-news') ) ); } /** * Helper function that holds widget fields * Array is used in update and form functions */ private function widget_fields() { $allrounder_news_Category_list = allrounder_news_Category_list($select = false); $fields = array( 'allrounder_news_section_title' => array( 'allrounder_news_widgets_name' => 'allrounder_news_section_title', 'allrounder_news_widgets_title' => esc_html__('Section Title', 'allrounder-news'), 'allrounder_news_widgets_field_type' => 'text', ), 'allrounder_news_blog_cat_category' => array( 'allrounder_news_widgets_name' => 'allrounder_news_blog_cat_category', 'allrounder_news_widgets_title' => esc_html__('Select Post Categories', 'allrounder-news'), 'allrounder_news_widgets_field_type' => 'multicheckboxes', 'allrounder_news_widgets_field_options' => $allrounder_news_Category_list ), 'allrounder_news_blog_posts' => array( 'allrounder_news_widgets_name' => 'allrounder_news_blog_posts', 'allrounder_news_widgets_title' => esc_html__('Posts Per Column', 'allrounder-news'), 'allrounder_news_widgets_field_type' => 'number', ), ); return $fields; } /** * Front-end display of widget. * * @see WP_Widget::widget() * * @param array $args Widget arguments. * @param array $instance Saved values from database. */ public function widget($args, $instance) { extract($args); $widget_title = apply_filters( 'widget_title', empty( $instance['allrounder_news_section_title'] ) ? '' : $instance['allrounder_news_section_title'], $instance, $this->id_base ); $allrounder_news_blog_cat_categories = isset( $instance['allrounder_news_blog_cat_category'] ) ? $instance['allrounder_news_blog_cat_category'] : '' ; $allrounder_news_blog_posts = isset( $instance['allrounder_news_blog_posts'] ) ? $instance['allrounder_news_blog_posts'] : '5' ; if($allrounder_news_blog_posts == ''){ $allrounder_news_blog_posts = '5'; } echo $before_widget; if( $widget_title || $allrounder_news_blog_cat_categories ){ ?>
$value){ $random_car_array[] = $key; } $query = new WP_Query(array( 'post_type' => 'post', 'tax_query' => array( array( 'taxonomy' => 'category', 'field' => 'slug', 'terms' => $random_car_array, ), ), ) ); $random_post_array = array(); if( $query->have_posts() ){ while( $query->have_posts() ){ $query->the_post(); $random_post_array[] = get_the_ID(); wp_reset_postdata();} $random_post_array = array_chunk($random_post_array, $allrounder_news_blog_posts); ?>
'post', 'posts_per_page' => -1, 'post__in' => $posts_ids, )); if( $popular_main_trip_query->have_posts() ){ ?>
have_posts()){ $popular_main_trip_query->the_post(); if($posts_count == '1'){?>

widget_fields(); foreach ($widget_fields as $widget_field) { extract($widget_field); $instance[$allrounder_news_widgets_name] = allrounder_news_widgets_updated_field_value($widget_field, $new_instance[$allrounder_news_widgets_name]); } return $instance; } public function form($instance) { $widget_fields = $this->widget_fields(); foreach ($widget_fields as $widget_field) { extract($widget_field); $allrounder_news_widgets_field_value = !empty($instance[$allrounder_news_widgets_name]) ? $instance[$allrounder_news_widgets_name] : ''; allrounder_news_widgets_show_widget_field($this, $widget_field, $allrounder_news_widgets_field_value); } } }