WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

    if (have_posts()) : while (have_posts()) : the_post(); ?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    endwhile; endif;

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
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
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(); ?>

    $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


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.