The MU forums have moved to WordPress.org

WPMU Featured Posts (4 posts)

  1. Romik84
    Member
    Posted 13 years ago #

    Hi again,

    I try to use this function to get featured posts in the last 30 days:

    <?php
      function filter_where($where = '') {
        $where .= " AND post_date > '" . date('Y-m-d', strtotime('-30 days')) . "'";
        return $where;
      }
    add_filter('posts_where', 'filter_where');
    query_posts($query_string);
    ?>

    I don't know how to show last posts from 30 days + choose posts with at least or 2 comments. Is that possible? I have seen $wpdb function comment_count >= but I don't know how to include that and get it working together. Thanks.

  2. Romik84
    Member
    Posted 13 years ago #

    anyone has idea please?

  3. Romik84
    Member
    Posted 13 years ago #

    Just trying this code. No luck. What am I doing wrong?

    <?php function featured_posts(){
    
    global $wpdb;
    
    $date = date('Y-m-d', strtotime('-1 months'));
    $date2 = date('Y-m-d', strtotime('-1000 days'));
    $days = (strtotime($date2) - strtotime($date)) / (60 * 60 * 24);
    $duration = $days;
    
                 $request = "SELECT ID, post_title, COUNT($wpdb->comments.comment_post_ID) AS 'comment_count' FROM $wpdb->posts, $wpdb->comments";
                 $request .= " WHERE comment_approved = '1' AND $wpdb->posts.ID=$wpdb->comments.comment_post_ID AND post_status = 'publish'";
                 if(!$show_pass_post) $request .= " AND post_password =''";
                 if($duration !="") $request .= " AND DATE_SUB(CURDATE(),INTERVAL ".$duration." DAY) < post_date ";
                 $request .= " GROUP BY $wpdb->comments.comment_post_ID ORDER BY comment_count DESC LIMIT $popularpostnumber";
                 $posts = $wpdb->get_results($wpdb->prepare($request));
                 if ($posts):
                  echo '<ul>';
                  foreach ($posts as $post):
                   setup_postdata($post);
                   $post_title = stripslashes($post->post_title);
                   $comment_count = $post->comment_count;
                   $permalink = get_permalink($post->ID);
                   echo '<li><a href="' . $permalink . '" title="' . $post_title.'"><span class="entry">' . $post_title . ' <span class="details inline">(' . $comment_count.')</span></span></a></li>';
                  endforeach;
                  echo '</ul>';
                 else:
                  _e("Didn't find any featured posts");
                 endif;
    
      }
    ?>
  4. Romik84
    Member
    Posted 13 years ago #

    ok, now I got it. As I use the sitewide tag plugin, I cannot call the posts per comments as the plugin doesn't support the comments indexing. But with a sitewide recent post plugin it seems to be possible....

About this Topic