• vickilh2

    (@vickilh2)


    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

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    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

    Thread Starter vickilh2

    (@vickilh2)

    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

    Thread Starter vickilh2

    (@vickilh2)

    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

    Thread Starter vickilh2

    (@vickilh2)

    P.S.

    And be sure to close your $posttime if with:

    <?php } ?>

    .. before you close off the main loop:

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

    and better if can query 2 different custom fields

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Future posts problem’ is closed to new replies.