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?
- PHP unit testing WordPress?
- Proper use of Output Buffer
- Include a external PHP file into a WordPress Custom Template
- List of all theme customizer control types?
- Is having multiple theme customizers for different pages possible?
- How to get year, month and hour in WordPress?
- The best way to customize “nav-menu-template.php” to add if the ‘link_before’ is “checkbox”
- Multiple do_shortcode($content) within one shortcode
- Advanced Custom Fields Image Field returning ID instead of URL [closed]
- Widgets not showing in my custom theme
- Can an array be used as a meta_query value?
- What is the fastest way to load PHP functions that are only used in one theme template?
- ACF check if variable has http, if else return string
- How do I access the media settings
- Can’t load WP function into external function
- Implement toggle switch for theme options in settings API
- How can i upload images in an admin page?
- Displaying the Month and Year that a page was Created?
- Wp-login appears White Screen, Error: Cannot modify header information
- ACF: how do I get the fields and its values of a specific group?
- Can’t access variable outside for loop
- add custom link to wordpress media gallery modal
- Need Help Fixing My Iframes [closed]
- Remove the first 5 characters of the_title and orderby that
- Compare the old get_theme_mod($name) to the new get_theme_mod($name) return value
- How do I link a button I created in theme customizer to a function?
- can i fetch a custom metabox data in another page or post type?
- ‘Post-thumbnails’ feature does not seem to register
- WordPress admin-ajax.php
- How to obtain the current website URL in my theme?
- Admin ToolBar not being displayed at top of site
- Separation of presentation and code – WordPress
- Search form does not work in my website
- get_template_directory adding FTP root folders in urls
- ACF put a comma after the last repeater field value [closed]
- Show ACF field with link to ultimate member profile/WordPress user profile below the post (single post layout)
- Live to Local on MAMP, not working, outputting functions.php code
- How to Update an old theme for the latest wordpress version
- Adding Updated Post Date PHP Custom Theme
- Search only working on front page (index) , not working on other pages
- Including Custom fields within the_content
- Toolbar Hidden in a Virtual Page
- Update user repeater meta (ACF) with another user meta field value
- How do I edit the terms output args or array data?
- Issue in displaying the ongoing event and current events in the post
- When I click for the redirect link it is showing the content of index.php instead of single_assignment_page.php
- ACF Taxonomy field values not select in backend
- How can I prevent a shortcode div from extending beyond its boundaries?
- Use WPQuery to match to specific repeater row in post
- Advance custom fields variable with if statement & Function
- Should I set a page as “No-index” if I include it’s content within the front-Page.php via this method?
- Place product field value as variable in php
- Warning: count(): syntax problem of the count () function
- Get list of posts from attachment
- How to output values from a loop into a javascript array
- WordPress child theme, creating a custom php template page
- Menu to the right of screen on desktop using Bootstrap 4
- Custom theme admin-ajax.php 400 (Bad Request)
- How to send Ajax Call from frontend without using wp_localize_script in Theme
- Add Text Area To Child Theme’s Home Page
- Comparing Dates within plugin using PHP If statement
- Array sorting assistance
- How to add thumbnails from recent posts to owl-carousel in wordpress automatically?
- Custom theme: adding unwanted tags in the content
- Relative post date in recent posts list
- append links with unique number string
- the_post_thumbnail unless video id is added
- Adding Media button to only pages
- How to implement conditional PHP in Footer
- Adding php within a return statement [closed]
- Pagination not working properly
- How can I fix my pagination?
- How to store the_post_thumbnail() value in a variable
- Custom WordPress Function – Adding items from Foreach Loop into an array and Updating Field based on array of IDs (ACF + WooCommerce)
- Creating posts with php-script + csv
- functions.php doesn’t load all custom theme assets
- Capture the Selected Radio Button Value between two files in wordpress theme
- WordPress move current to top in the loop
- Advanced Custom Fields Auto Populating Field Values For Nested Repeater FIelds
- Alter main query to always list posts according to ACF number field
- Add css class ID to largest and smallest number a custom field in wp_query