I have a custom template that is using the loop to grab post info to build a custom slider and it is working perfectly. The client gave a new requirement that they only want posts from the last 2 days to be displayed in the slider.
Within the loop I added the following if statement:
$today = date('j');
if ( have_posts() ) :
while ( have_posts() ) :
the_post();
// Added the below code
if (the_date('j','','',FALSE)>($today-3)) :
// Builds slide
endif;
// End of new code
endwhile;
else:
?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php
endif; ?>
When this code is added the loop only displays a single post, the first post which is found to meet this IF statement’s condition, and does not display any others. I have manually changed the dates so that at least 3 posts have publish dates within the last two days, still nothing.
When I uncomment the above lines the code works fine and pulls all posts to be built into slides.
I cannot use the “posts_where” filter as this affects the other posts on the page (Imagine the slider at the top of the page, and posts below the slider).
Is there something I am missing? Or can the_date() not be used like this?
I’ve had the same problem, try using
Could this be your problem – as per the ‘special note’ on the documentation for
the_date
at http://codex.wordpress.org/Template_Tags/the_date:So use
get_the_date
, as documented here: http://codex.wordpress.org/Template_Tags/get_the_dateFor example
if (get_the_date('j') > ($today-3)) :
etc.
Don’t ask why, and if you can explain why please do in the comments, but had to do something like this:
This is working for me
the_time('d/m/Y');
Use get the date function.
Why the_date is not working but get_the_date is working?
https://wordpress.stackexchange.com/questions/166751/post-doesnt-show-date-if-theres-another-post-with-the-same-date
See kaiser’s answer from the above link.