How to sort top rated posts by date?
-
Great plugin, thank you!
I need to sort the TOP 5 list posts by date, so that I’ll get only the top rated posts from the last 30 days. The top five list should only show the posts that were published withing last 30 days.
This is the function of the plugin:
if ( ! function_exists( 'thumbs_rating_top_func' ) ): function thumbs_rating_top_func( $atts ) { $return = ''; // Parameters accepted extract( shortcode_atts( array( 'exclude_posts' => '', 'type' => 'positive', 'posts_per_page' => 5, 'category' => '', 'show_votes' => 'yes', 'post_type' => 'any', 'show_both' => 'no', 'order' => 'DESC' ), $atts ) ); // Check wich meta_key the user wants if( $type == 'positive' ){ $meta_key = '_thumbs_rating_up'; $other_meta_key = '_thumbs_rating_down'; $sign = "+"; $other_sign = "-"; } else{ $meta_key = '_thumbs_rating_down'; $other_meta_key = '_thumbs_rating_up'; $sign = "-"; $other_sign = "+"; } // Build up the args array $args = array ( 'post__not_in' => explode(",", $exclude_posts), 'post_type' => $post_type, 'post_status' => 'publish', 'cat' => $category, 'pagination' => false, 'posts_per_page' => $posts_per_page, 'cache_results' => true, 'meta_key' => $meta_key, 'order' => $order, 'orderby' => 'meta_value_num', 'ignore_sticky_posts' => true ); // Get the posts $thumbs_ratings_top_query = new WP_Query($args); // Build the post list if($thumbs_ratings_top_query->have_posts()) : $return .= '<ol class="thumbs-rating-top-list">'; while($thumbs_ratings_top_query->have_posts()){ $thumbs_ratings_top_query->the_post(); $return .= '<li>'; $return .= '<a href="' . get_permalink() . '">' . get_the_title() . '</a>'; if( $show_votes == "yes" ){ // Get the votes $meta_values = get_post_meta(get_the_ID(), $meta_key); // Add the votes to the HTML $return .= ' (' . $sign; if( sizeof($meta_values) > 0){ $return .= $meta_values[0]; }else{ $return .= "0"; } // Show the other votes if needed if( $show_both == 'yes' ){ $other_meta_values = get_post_meta(get_the_ID(), $other_meta_key); $return .= " " . $other_sign; if( sizeof($other_meta_values) > 0){ $return .= $other_meta_values[0]; }else{ $return .= "0"; } } $return .= ')'; } } $return .= '</li>'; $return .= '</ol>'; // Reset the post data or the sky will fall wp_reset_postdata(); endif; return $return; } add_shortcode( 'thumbs_rating_top', 'thumbs_rating_top_func' ); endif;
How do I add filter to get posts for the last 30 days?
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘How to sort top rated posts by date?’ is closed to new replies.