• I need to replicate how a Calendar’s “upcoming events” behaves, but with posts.

    This page will only display posts that match the current date, and future posts.

    Example: If today is June 1st, 2010, it will only show future-dated posts like June 10th, July 4th, August 12th, etc. It will NOT show any posts that are dated before June 1st, like May 10th or April 24th.

    I know this is more advanced than the average sort, but I hope this can be done!

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter Lasha

    (@lasha)

    I found this bit of code which somewhat solves the problem. My guess is that this code goes in the functions.php file.

    How do I make it so this date filter only applies to posts being retrieved on a custom page template? I don’t want it to effect the whole blog.

    http://codex.wordpress.org/Function_Reference/query_posts#Time_Parameters
    Return posts for posts for March 1 to March 15, 2009:

    <?php
    //based on Austin Matzko’s code from wp-hackers email list
    function filter_where($where = ”) {
    //posts for March 1 to March 15, 2009
    $where .= ” AND post_date >= ‘2009-03-01’ AND post_date < ‘2009-03-16′”;
    return $where;
    }
    add_filter(‘posts_where’, ‘filter_where’);
    query_posts($query_string);
    ?>

    I have a custom page that displays posts like so:
    http://codex.wordpress.org/Pages#A_Page_of_Posts

    With my scenario, I would only set the filter to “post_date >= the_date(‘Y-m-d’)” but where does this go? How do you apply this filter to the custom $wp_query?

    query_posts usage

    <?php
    
    //The Query
    query_posts('posts_per_page=5');
    
    //The Loop
    if ( have_posts() ) : while ( have_posts() ) : the_post();
     ..
    endwhile; else:
     ..
    endif;
    
    //Reset Query
    wp_reset_query();
    
    ?>
    Thread Starter Lasha

    (@lasha)

    Where exactly would I add the filter in that block of code?

    between
    //The Query
    and
    //The Loop

    Thread Starter Lasha

    (@lasha)

    Yes, I understand this, but doesn’t the add_filter need to be in the functions.php page?

    If so, how do I pass the “post_date >= the_date(‘Y-m-d’)” filter to the add_filter function, and make the query_posts recognize it?

    I don’t know :p
    maybe by calling the function
    filter_where();

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Sort posts by UPCOMING dates’ is closed to new replies.