Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to create a page labeled "Today's News" which displays a simple bulleted list of all posts published on the current day and grab the current date based on the server's date/time. Is this feasible?

Thank you for any help.

share|improve this question
add comment

2 Answers

Use query_posts

$day = date('j');
query_posts( "day=$day&order=ASC" );
share|improve this answer
add comment

Is this feasible?

Yes.


get_posts(); is your best friend. No need to modify the query or run a new one.

// Call it with the date you need as input argument
function wpse28632_get_daily_posts( $date = null )
{
    $posts = get_posts( array( 'order_by' => 'post_date' ) ); // additional arguments - see Codex
    echo '<ul>';
    foreach ( $posts as $post )
    {
        if ( $date == $post->post_date )
            echo "<li>{$post}</li>";
    }
    echo '</ul>';
}
share|improve this answer
    
What is there are thousands of posts - should you get all of them just to list today's ones? –  Darhazer Sep 15 '11 at 18:07
    
If there are about hundreds of thousand, both visitors & posts, then you could try to do a direct SQL query for a better performance. Else the index just works fine. Also: get_posts(); is nothing else than a new WP_Query. This has two advantages: 1) It's easier than doing a new query, saving the object and picking the stuff you need and the args are partly shared with query, but just simplified. Imo array is easier to understand for most than object. 2) Less chance to make failures. If you don't save the result in some var, it will be performed, but nothing happens. –  kaiser Sep 15 '11 at 23:43
1  
@Darhazer. Btw: Read here for better insights. Andrej fetched it up pretty well. –  kaiser Sep 16 '11 at 0:02
add comment

Your Answer

 
discard

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.