Support » Fixing WordPress » Post Dates that indicate Today, Yesterday, or the post date

Viewing 2 replies - 1 through 2 (of 2 total)
  • whooami

    (@whooami)

    Member

    Fancy I see you here. It seems we both are pondering the same thing. Well, I found a solution although I’m having problems with actual date it is interpreting (today is the 21st, but all of sudden it’s declaring itself as tomorrow 22nd).

    Anyways, here is what I have to display posts published for “Today”:

    // Capture today's date
    $today = getdate();
    
    // Set WP Query arguments
    $argsT = array(
    	'cat'=>3,
    	'year'=>$today["year"],
    	'monthnum'=>$today["mon"],
    	'day'=>$today["mday"]
    	);
    
    // Create a new instance of the object
    $todayQuery = new WP_Query($argsT);
    
    // Loop through posts published "Today"
    <?php if ($todayQuery->have_posts()) : ?>
    <?php while ($todayQuery->have_posts()) : $todayQuery->the_post(); ?>
    <a href="<?php echo $link; ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
    <?php endwhile; ?>

    My only problem is the getdate() function is much faster than what the actual time is….not sure why but I’m still figuring that out.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Post Dates that indicate Today, Yesterday, or the post date’ is closed to new replies.