Jump to content

Display “Today” Instead of Date for Pubslished Posts


sunziun

Recommended Posts

I have a list of 'post_status'' => 'future' which are published at certain dates throughout the year. These posts are custom posts whith Advanced Custom Fields.

Since a couple of days I'm trying to display "Today" of published posts (for that particular day). The word "Today" should only display if date of the post equals the current date otherwise the the scheduled posts should be displayed.

The query which looks like this display future posts:

$future= new WP_Query(array(    'post_type' => 'hijama_days',    'date' => date('d/m/Y'),    'posts_per_page' => 1,    'order' => 'ASC',    'post_status' => 'future',));

The loop looks like this:

while ( $future->have_posts() ) : $future->the_post();// next line is from Advanced Custom Field Docs$gdate = DateTime::createFromFormat('Ymd', get_field('gregorian_date'));

I've tried this to display "Today" when the current event has been pusblished for that day:

$currentdate = new DateTime();<p>When is the next event date?</p><?php if( $gdate->format('d/m/Y') == $currentdate->format('d/m/Y') ){ ?>   <h1>Today</h1><?php } else { ?>   <h1><?php echo $gdate->format('l') . ' '; the_title(); ?></h1><?php } ?>   <h4>Gregorian: <?php echo $gdate->format('d/m/Y'); ?></h4>

Somehow I cannot figure why is not working for me.

Please help me out here.

Link to comment
Share on other sites

Hi Justsomeguy,

 

thanks for your reply.

 

Actually nothing happens or it displays just the future posts. I might be missing some bits but I don't know what.

 

Maybe it help you to understand more if access the website at hijamadays.com

Link to comment
Share on other sites

what are these values when the loop runs?

$gdate->format('d/m/Y') $currentdate->format('d/m/Y')

maybe you just didn't have the right data to display "Today"?

Link to comment
Share on other sites

Hi thescientist,

 

$gdate is a custom field from Advanced Custom Fields Plugin.

It's date field which should display Gregorian date like 15/03/2014.

 

$currentdate should grab the date of example 25/04/2014.

 

And what I want is: If $gdate is equal to $currentdate then display "Today".

Otherwise display the standard data from the loop.

 

This is somehow not working properly or it displays just the normal loop.

 

I have even tried to use $currentdate->setDate(2014,04,25) for testing purpose.

Edited by sunziun
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...