Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

To display the most popular posts based on page views I am using this code (source):

<?php
    query_posts('meta_key=post_views_count&orderby=meta_value_num&order=DESC');
    if (have_posts()) : while (have_posts()) : the_post(); ?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    <?php
    endwhile; endif;
    wp_reset_query();
?>

I would like to restrict the query to return posts from a certin date (i.e. the last seven days) and I am unsure how I would achieve this.

share|improve this question
    
Please.... don't use bold everywhere... doesn't make your question more important. And please don't use query_posts(). –  kaiser Apr 30 '13 at 14:56
    
I never claimed it made it more important, I was simply highlighting what the actual question was. But I'll change it so it doesn't bother you so much. Also - I thought this site's policy was only constructive answers? Telling me not to use bold and not providing a workable answer isn't exactly constructive. –  AndrettiMilas Apr 30 '13 at 15:05
1  
Have a look at WP_Query() -- there's a snippet of code there labeled Returns posts for just the current week that might be just what you're looking for. –  Pat J Apr 30 '13 at 15:07
    
Thanks @PatJ I will look into that. –  AndrettiMilas Apr 30 '13 at 15:09

1 Answer 1

up vote 1 down vote accepted

I've done something in the past using custom fields. Maybe this can get you going in the right direction? This is done directly after the <?php while ( have_posts() ) : the_post(); ?>

<?php
    $currentdate = date("Ymd");
    $expirationdate = genesis_get_custom_field('_racedate');
    $expirestring = str_replace("-","",$expirationdate);
        if (is_null($expirationdate)) {
            $expirestring = '30005050'; //MAKE UN-EXPIRING POSTS ALWAYS SHOW UP;

        } else {

        if (is_array($expirationdate)) {
            $expirestringarray = implode($expirationdate);
        }

        } //else
        if ( $expirestring + 1 > $currentdate ): ?>

This will actually show up everything that has been posted (in my case, future races) and a day after the "racedate", the post would disappear from the loop (it still remains in the dashboard).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.