This:
date( 'Y-m-d', strtotime('-6 hours') );
Is going to spit out something like 2011-11-11
If your date picker is using the format dd-mm-yy
, then comparing the two is not going to work. dd-mm-yy
, if it’s what’s in the field on post save/update, is what’s going to be saved as the meta_value
.
The meta value is likely getting saved as a string, which is fine — you can still do date comparisons, but the formats have to match. There are a few options for solving this:
- Convert your dates to unix time stamps before saving them in the
database — usestrtotime
— do the reverse on
the front end:date( 'F, j Y', $some_time_saved_in_db );
to show the dates to users. Comparing timestamps should be the most reliable. - Save your field with the ISO standard date format,
YYYYMMDD
, which
works fairly well for comparing/sorting dates.
Related Posts:
- How to sort CPT by custom meta value (date), and return posts month by month
- Meta Query posts not showing on ending date of custom field
- Sort custom post type by most current date picker
- How to display a WordPress Custom Field only on a specific day of the week?
- How to sort WP_Query by a custom text field (written as a date dd/mm/yyyy)
- Pre_get_posts comparison with custom field doesn’t work
- Get month and day from a Date Picker custom field
- How to get past and upcoming post by defining date in custom field?
- How to display custom post type ordered by a custom field date
- Is it possible to specify a time interval (from, to) in ACF with date picker, or other custom field?
- How to display *block number* instead *date value* on WordPress posts?
- Advanced search form with filters for custom taxonomies and custom fields
- Help Creating a Slideshow Custom Post Type with Custom Meta Boxes?
- How to order posts of a custom post type by date DESC in dashboard Admin?
- Search multiple custom fields by using meta_query
- Custom Post Type – Taxonomy Dropdown Menu?
- How do I implement custom fields without using any plugins?
- How I check if the same post slug has not been used before publishing?
- How to sort a table of custom posts by column containing custom field
- Issue with saving custom post type when editor is removed
- order by meta_value serialized array
- Date query for a custom meta field
- convert Custom Fields Option-Values to Tags/Taxonomy
- Custom post metadata not appearing in public API
- How to make an archive page displaying posts in a date range
- Automatically Insert Custom Field on Custom Post Type Publish
- Display custom post types with custom date field value (before today) & order by custom date field
- How to have the right design for a custom post type without accessing themes
- Create a post in custom post type using field in registration form after users submit form
- WordPress custom meta field for custom post not storing data
- Conditional regex in add_rewrite_rule() for specific query filters & pagination
- How to Duplicate (multiple meta box)?
- List all images from a single post meta value
- Publish an XML feed from a CPT with ACF fields?
- WP_Query: include custom post type only with specific meta value
- Is there a way to get a file URL from the relationship ACF field?
- Meta Key Value in current-user-only loop
- How can I dynamically add a post to a custom post type which uses a custom field?
- dynamically add a custom field or metabox to custom post type [duplicate]
- How to implement a Google map store locator
- Random image from tag/custom type on sidebar
- retrieve Meta field value from CPT and set those values as Image Meta Field “Title”
- Set a maxlength for the title input in a custom post type
- Update Post Meta for a logged in user
- Problem querying Custom post type by custom fields
- Using custom field content as expression in IF statement [closed]
- ACF From & To Date Validations
- Query Multiple Custom Posts by Custom Fields
- Custom REST endpoints for a custom post type with custom fields
- Homepage’s content is dependent on the custom field values (set automatically), how do I get homepage to update without manually updating page?
- Cross reference custom post types
- frontend image post uploader
- Custom Post Fields at the beginning of a Custom Permalink
- Possible to filter custom post type with multiple meta data?
- Order post by date with ACF
- Show fields based on taxonomy selection in editor
- Permalinks: custom structure for taxonomy – tags?
- How to Get the title of a custom field?
- How to customize work area / admin area in a custom post type without plugins?
- ACF in wordpress
- delete_post_meta() for whole CPT / multiple posts?
- How to inherit field value from parent post into in child / sub post
- hide specific div on single.php [closed]
- How to get_term_meta on single custom post?
- How do you output an unknown number of images in a custom post type with desired markup?
- How to fetch custom post types with its full data on wordpress?
- Custom Fields not showing up for custom post type
- Custom post type in Custom widget – $listItem
- Generating and downloading files with WP API
- Using WP meta query to show custom post types by a start and finish date
- Add a class to post_class if more than one post shares same meta_value_num
- Add a meta field to the list of results for a custom post type
- Front-end Image Upload to Custom Meta Box
- How do I list a custom field and custom taxonomies for each result in a loop?
- Adding a location field to buddypress activity
- Display Posts that fit a certain criteria on Category pages
- Sort custom post column by generated value?
- How to only display all posts to a custom User Role?
- Unable to gather Image URL from Custom Post Type’s; Custom Meta Field
- register_rest_field update_callback don’t work for $_FILES
- How to convert Post Object Custom Field into Tags
- Custom meta fields not showing up in WP_Response Object via custom endpoint
- Query a Custom Post Type using SELECT that has ACF fields to compare dates
- I want to create a metabox under custom taxonomy
- Filter custom WP_Query by first letter of a custom field – hopefully using Search and Filter Pro?
- PHP Notice: Unidentified index
- check_admin_referer not working in custom meta box for custom post type
- How to display all custom fields associated with a post type – IN THE ADMIN AREA?
- group posts by month/date ignore years
- Setting a custom $query->query_vars[‘meta_key’] breaks the WordPress menu
- WP_Query and two custom fields returns no posts
- I want to split this into two functions
- Repeatable Custom Field for Media Upload
- How to store datetime from custom meta box so that it can be sorted by
- Custom Post Meta on a Different Page?
- Adding a custom field after post title (ex.Example Title [30 Second Read])
- querying to custom field over ACF REST API
- Send email on creation of custom post type and use get_post_meta()
- Post object GUID adding http:/
- WordPress does not show the custom fields box