$afb->_("This widget shows most popular post per post type."), "classname" => "anyway-feedback-popular-widget" ) ); } /** * Retrive */ function widget($args, $instance){ global $wpdb, $afb; extract( $args ); $title = empty($instance['title']) ? $this->name :apply_filters('widget_title', $instance['title']); $post_type = empty($instance['post_type']) ? 'post' :esc_attr($instance['post_type']); $num_posts = empty($instance['num_posts']) ? 5 : esc_attr($instance['num_posts']); $sql = <<table} AS afb LEFT JOIN {$wpdb->posts} AS post ON afb.object_id = post.ID AND afb.post_type = post.post_type WHERE afb.post_type = %s ORDER BY positive DESC LIMIT %d EOS; $posts = $wpdb->get_results($wpdb->prepare($sql, $post_type, $num_posts)); ?> posts} WHERE post_type NOT IN ('draft', 'revision', 'nav_menu_item', 'attachment') GROUP BY post_type ORDER BY post_type ASC"; $results = $wpdb->get_results($sql); ?>