sunziun Posted April 19, 2014 Share Posted April 19, 2014 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 More sharing options...
justsomeguy Posted April 21, 2014 Share Posted April 21, 2014 That if statement is correct. What happens when you run that? Link to comment Share on other sites More sharing options...
sunziun Posted April 23, 2014 Author Share Posted April 23, 2014 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 More sharing options...
justsomeguy Posted April 23, 2014 Share Posted April 23, 2014 I don't know what I'm supposed to be looking for. I see it displaying a date that is not today, which sounds correct. Link to comment Share on other sites More sharing options...
thescientist Posted April 23, 2014 Share Posted April 23, 2014 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 More sharing options...
sunziun Posted April 25, 2014 Author Share Posted April 25, 2014 (edited) 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 April 25, 2014 by sunziun Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now