Forums

Future posts problem (6 posts)

  1. vickilh2
    Member
    Posted 3 years ago #

    I'm a newbie, and I've been pulling my hair out on this one.

    I wanted to order my posts ascending on a page, so I couldn't go with the generic query. I also want my posts to "age out".

    I got the ordering to work, no problem:
    $posts = query_posts($query_string.'&orderby=post_date&order=asc&posts_per_page=30'); ?>

    ... But I haven't been able to get rid of old posts. I tried this various ways: '&post_date>=NOW()' or using monthnum, etc., but these ONLY appear to accept "=", won't accept a greater than, >.

    I can't use 'post_status=future' because I changed the post.php code so that everything would go in with a status of 'publish' and would show up on the website.

    Any help greatly appreciated!! Vicki

  2. Otto
    Tech Ninja
    Posted 3 years ago #

    You can't do that so easily. The WordPress query code has no ability to select posts based on "age".

    If you manually want to screw around with the query, you need to use a filter on the various posts_* filters.

    Look here: http://codex.wordpress.org/Plugin_API/Filter_Reference#Advanced_WordPress_Filters

    Also see here for how to use them:
    http://codex.wordpress.org/Plugin_API#Filters

  3. vickilh2
    Member
    Posted 3 years ago #

    So I can't use boolean operators like ">" (greater than) in situations like this:
    http://codex.wordpress.org/Template_Tags/query_posts#Example_2
    ... where I would want to use ">" instead of "=" for monthnum=$current_month, etc.? I can only use "="?

    Thanks!! Vicki

  4. vickilh2
    Member
    Posted 3 years ago #

    Ha!! Got it working! Pretty simple really:

    <?php if (have_posts()) : ?>
    
    <?php $today2 = (date('Y-m-d H:d:s')); ?>
    <?php $today = strtotime($today2); ?>
    
    <?php
    $posts = query_posts($query_string.'&orderby=post_date&order=asc&posts_per_page=30&paged=$page'); ?>
    
                    <?php while (have_posts()) : the_post(); ?>
    
                    <?php $posttime = strtotime($post->post_date); ?>
    
                            <?php if ($posttime >= $today) { ?>

    Struggled for a while to get just the right syntax, but it just didn't make sense that this wouldn't work.

    Yay!! Hope this helps someone. Vicki

  5. vickilh2
    Member
    Posted 3 years ago #

    P.S.

    And be sure to close your $posttime if with:

    <?php } ?>

    .. before you close off the main loop:

  6. AlexNull
    Member
    Posted 3 years ago #

    it will be nice that query_posts accept >, <, !=
    :)

    and better if can query 2 different custom fields

Topic Closed

This topic has been closed to new replies.

About this Topic