Support » Fixing WordPress » Sort posts by UPCOMING dates

  • 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)
  • 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.
    Return posts for posts for March 1 to March 15, 2009:

    //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’);

    I have a custom page that displays posts like so:

    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

    //The Query
    //The Loop
    if ( have_posts() ) : while ( have_posts() ) : the_post();
    endwhile; else:
    //Reset Query

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

    //The Query
    //The Loop

    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

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