What you did wrong here is the part date('d', $rem_days)
. The function date()
should be used to convert timestamp to a formatted date, not to converting a time difference in timestamp to time difference in days.
You can fix this by replacing date('d', $rem_days)
with floor($rem_days/86400)
.
The complete code should be:
$event_date = strtotime( get_field( 'event_date', false, false ) );
$curr_date = time();
$rem_days = $event_date - $curr_date;
if ( $rem_days <= 0 ) {
$event_msg = '<strong>Event Expired</strong>';
} else {
$event_msg = '<strong>' . floor( $rem_days / 86400 ) . '</strong> Days Remaining';
}
Note: As per Pat J’s comment, WordPress provides a bunch of handy {timespan}_IN_SECONDS
constants in wp-includes/default-constants.php
, including DAY_IN_SECONDS
.
So in the above code, floor( $rem_days / 86400 )
can be replaced with floor( $rem_days / DAY_IN_SECONDS )
Related Posts:
- Conditionally loading JavaScript based on the Advanced Custom Fields in the post
- WordPress returns a wrong date
- Unable to set right time in admin and frontend template
- display month in french in wordpress/php?
- Get date numerical and separate?
- Print last modified date only on posts
- How to get User Time Zone in WordPress?
- Using php inside javascript [closed]
- Get date function not working
- If Post Published Date or Modified Date is 1 Year or Older, Display Notice on Post Page
- WordPress wrong dates bug
- Possible to edit custom date field and display?
- Can’t add to time? [closed]
- Ordering / grouping posts by datepicker ACF
- Adding a number to a date
- Display Year and Month from custom field + Age Calculator
- ACF | WooCommerce | Theme Development | How to include a /template-part/ that makes use of ACF’s on a custom WooCommerce homepage?
- Convert custom field date format to “WordPress default”
- How to get ACF field to show up on all posts on front end?
- Hide categories that are not used in the post type
- ACF: how do I get the fields and its values of a specific group?
- How do I add custom bulk actions to multiple custom post types?
- Add_action not working in required file of functions.php
- How to set up VS Code for WP plugin/theme development in 2021? [closed]
- Why do WP_Query results change after updating unrelated Advanced Custom Fields (ACF)?
- Saving an array of dynamic repeater data as post_meta
- adding custom user input fields in WordPress admin dashboard gives error The link you followed has expired. Please try again
- what is the best practice to add new field to an api route
- Grab posts by multiple categories
- Can’t access variable outside for loop
- I have a problem in the order of enqueues while enqueuing stylesheets and scripts for a specific page in my function.php
- add custom link to wordpress media gallery modal
- Need Help Fixing My Iframes [closed]
- Output ACF repeater on frontend user’s profile page (created with Ultimate Member) [closed]
- Avoid parallax images hardcoding
- Improve page speed loading using CDN and async or defer attribute
- Remove the first 5 characters of the_title and orderby that
- Adding number to date not working [closed]
- Set meta field to publish date + 2 weeks
- Unread Repeater field IMG alt not working
- Unable to write multiple values back to ACF user field – PHP
- populate form fields in a loop with ajax
- Error in custom php function doesn’t exist
- Customizer: active_callback and sanitize_callback incompatibility?
- Update grandchild repeater field with value per row
- post created but no permalink
- How to use thumbnail size of image if I’m only using src to get image
- Slick + PHP + ACF + JQuery slide reveal not working
- Populate editor with some content of a page with a page template
- Two queries for a WP_User_Query search work perfectly apart, but not together
- Recent Posts Not Showing Only On A Specific Category Page [closed]
- Catchable fatal error: Object of class stdClass could not be converted to string after WP 4.7
- Menu jumping when calling it via PHP
- Displaying recent posts on static page with template-part via shortcode
- How to edit widget code to add unique class name to each div?
- Compare the old get_theme_mod($name) to the new get_theme_mod($name) return value
- Skt full width basic slideshow problem
- How to manually change current date to post date in frontend?
- How to disable controls in theme customizer?
- How do I link a button I created in theme customizer to a function?
- Trying to retrieve post meta
- Displaying custom field according to date
- Sort by page information by Ascending Numbers
- can i fetch a custom metabox data in another page or post type?
- Is there a way to conditionally check whether a WordPress post title is empty?
- Is the “_s” on this `sprintf(__(‘Page %s’, ‘_s’), max($paged, $page))` just refer to a text domain?
- Redirect to another page using contact form 7? [closed]
- get_template_part for specific page
- How do I create my own .php file with a code part and echo it on different pages?
- How to remove woocommerce_breadcrumb() from do_action( ‘woocommerce_before_main_content’ ); [closed]
- ‘Post-thumbnails’ feature does not seem to register
- if statement with is_active_sidebar()
- WordPress admin-ajax.php
- Use .php file as page instead of wordpress page & template file?
- Advanced Custom Fields – display label and value only if value entered
- Use WordPress function in php file
- What does this mean in wordpress? Easy question
- Advanced Custom Fields not displaying
- How to obtain the current website URL in my theme?
- Syntax error when I try to insert my loop into an unordered list? [closed]
- What exactly do this function declared into functions.php file of a WP theme?
- Admin ToolBar not being displayed at top of site
- Royalty-Free Sliders used in theme development
- Convert WordPress date format to jQuery UI Datepicker format
- Why am I getting a different filename? And how does WordPress load singular.php for both Page & Post? (Fresh WordPress installation)
- Converting Y-m-d to a date with a Month name? [closed]
- Find hours between post_date and post_date_gmt
- How to set up a If is_singular statement?
- Reason to add a name of the theme like (‘menu-1’ => __( ‘Primary’, ‘twentynineteen’ ),) in PHP?
- Underscore – Self hosted fonts
- Download PDF after CF7 form submission
- 3 different times on my WordPress website
- Separation of presentation and code – WordPress
- Search form does not work in my website
- Show About and Contact Us page when they’re clicked in the top menu.
- Is There A Way To Make Theme Files Accept Shortcodes?
- How to create an ACF shortcode with Repeater Field in WordPress? [duplicate]
- get_template_part() not firing within a switch statement when template has new WP_Query
- WordPress Customizer Default Image
- How to call multiple functions from multiple files into a WordPress page template [closed]