$current_date is a timestamp and $compare_date is a formatted date, so you’re comparing different things.
As you’re already using DateTime and as of PHP 5.2.2 DateTime objects can be compared using comparison operators, you can compare instead $expired_date (DateTime object) with today’s date as a DateTime object:
$current_date = new DateTime();
$expired = new DateTime();
$expired->setTimestamp( get_the_time('U') ); // get UNIX timestamp of current post
$expired->add(new DateInterval('P2D')); // add 2 days
$day_color="";
if( $current_date > $expired ) {
$day_color="#BA0000";
} else {
$day_color="#39AC00";
}
echo sprintf( '<span style="float: right; color: %s;">Due Date: %s</span>', $day_color, $expired->format('F j, Y g:i A') );
Related Posts:
- the_date() not working
- error_log() output for print_r() appearing on page
- Allow only 1 taxonomy per custom post type [duplicate]
- Custom plugin: Trying to show saved data on frontend
- Do I require the use of nonce?
- Fatal error: Call to undefined function plugin_dir_path()
- How to make WordPress plugin check for database changes and then do something?
- Retrieve multiple values passed to a single attribute in a shortcode
- How to change date language without changing the entire site language?
- Save selected item from dropdown menu in a meta box as a metadata value for a custom post type
- How to use copy() function and paste file in /wp-content/themes directory
- OOP Plugin Development. Including external object
- Authenticating to WordPress, using my own authentication two-factor system
- WordPress returns a wrong date
- Use composer to load custom classes [closed]
- wordpress custom endpoint multiple params
- Why when I instantiate wp_error in a validation method my user registration method stops working?
- Create table in database when activating plugin
- Problem with WordPress Ajax form
- allow user to select pages from dropdown in my plugin
- Am I not understanding plugins?
- Using Font Awesome as post thumbnail
- How to set a custom path, for ajax image upload folder in admin?
- admin-ajax.php responding with 0
- Page Reloads Before AJAX Request Finishes
- Add htaccess rules with insert_with_markers at beginning of htaccess
- custom shortcode will not display the wrapped content
- How to restrict wp generate attachment metadata() to certain intermediate image sizes
- Insert array data on plugin activation
- WordPress php filter admin_body_class not working
- Common abstract class for plugins
- Same log message keeps on printing to debug.log file thousand of times
- Adding Default Settings to Theme My Login plugin
- Append HTML Using Shortcode
- Create onClick Event to Re-load a Widget
- Accessing the database from a plugin outside of action hooks
- Adding subdomain to home_url for “add_menu_page”
- How to select the contents in the text view textrea in wp_editor?
- Hide categories that are not used in the post type
- Automated Cart Update With Alert Box Each Time
- WooCommerce/WordPress: how hide entire table form after submit (Admin Dashboard)?
- How to sanitize any integer input field in wordpress?
- WordPress ajax doesn’t display object method on jQuery .change() function
- filter default query to show just selected level of child pages in wordpress
- Adding number to date not working [closed]
- Set meta field to publish date + 2 weeks
- How to make my custom widget appear within WordPress widgets? Plugin development
- How to auto fetch customer details in Woocommerce in checkout page
- Can’t upload image using media_sideload_image
- Adding widgets to my plugin page instead of WordPress dashboard
- How to insert data into database using wp cron job
- I want to add custom add to cart link [closed]
- Execute long and heavy processes
- Access Child Class of Plugin Main Class Instance
- How can I hide that I Use WordPress (with W3 Total Cache)
- Saving plugin settings – ERROR: options page not found
- class_exists returns different values [closed]
- Custom array from a query only write the last row of the query
- Is it possible to define variables in a wordpress shortcode, and then call the shortcode using a specific variable?
- Change product_base programmatically
- How to remove the message ‘We could not find any results for your search’ without changing template files and without adding posts/pages?
- Custom meta box values are not getting saved for my custom post type
- Can’t upload CSV file to plugin directory using custom upload form in admin panel
- Validate and Sanitize WP REST API Request using WP JSON Schema?
- Set default Database Storage Engine when creating tables with plugins?
- Can I remove or edit an include() from a function with a filter?
- Call to undefined function error in plugin
- How do I make this Metabox show current DB value?
- Execute Jquery when a specific page in my plugin is loading
- Get category id when SEO URL is turned on
- Using ACF Relationship field to set post type to draft or published status
- How to extend SelectControl with data from my theme
- Trying to use a variable to set image width
- How can i avoid duplicate same post in wp?
- How do I disable cache for a certain page?
- How to check if plugin update process completed in wordpress?
- How to identify which php file a plugin is using on page load?
- dashboard widget form not submit mails
- using filter and hook inside class
- Priority call methods – PHPMailer->addAddress(NULL)
- How to properly escape in ternary operators – Wp Coding Standards?
- Add Admin Option w/ Anonymous Function
- defined (‘ABSPATH’) false after AJAX post to other PHP-file
- How to send logs to plugin owner for a plugin?
- Getting Member Data From WhishList Member on Register
- Private messaging – Getting and displaying the avatar/url of a message recipient
- Display Year and Month from custom field + Age Calculator
- widget: input the px value from user and use it as inline style in widget function
- Custom post type single page return to listing page
- WordPress rewrite question
- Using Nonce for my Form
- Create new folder and upload files to custom folder via wp_handle_upload
- SHARING TO FACEBOOK – FROM DYNAMICALLY GENERATED PAGE
- Implement OAuth2 in custom plugin
- login redirect based on user role not work as expected
- redirect user from login page if is logged
- How to lock users account until approvation
- Variable ++ in query loop
- WordPress REST API – Custom field not added to pages
- Cannot register a custom WP-CLI command