Drew, one thing about your code above is that the word dateAllergy should be in quotation marks like. I’m not sure of that is the problem but it’s worth changing.
$datefield = get_post_meta($post_id, 'dateAllergy' ,true);
Also, I just noticed that your $post_id variable will be empty too. You should change that to $post->ID. That would explain why duplicate posts are being created because it the value is null or empty, WordPress will create a separate post
Related Posts:
- Query current and future events, ordered by begin date
- Order post by date with ACF
- Using WP meta query to show custom post types by a start and finish date
- Get month and day from a Date Picker custom field
- Is it possible to specify a time interval (from, to) in ACF with date picker, or other custom field?
- Custom Post Type Archives by Year & Month?
- Getting custom taxonomy from custom post type
- Filter next_post_link() and previous_post_link() by meta_key?
- How to order posts of a custom post type by date DESC in dashboard Admin?
- Automatically fill custom field value on post publish/update
- Make permalinks based on an ACF-field
- How to sort a table of custom posts by column containing custom field
- List events by month
- Date query for a custom meta field
- Use Custom Post Type as Custom Field
- How to make an archive page displaying posts in a date range
- Pull image from ACF field in a Custom Post Type
- Archive filter disappears on no results?
- Get the next event using date_query
- WordPress custom post type archive with description
- wp_update_post based function works on existing posts, but not new posts
- How to Display ACF Relationship Custom Field as Link to Specific Custom Post?
- How to replace custom post type slug with an ACF value?
- Link users to a custom post type
- Custom Post type with ACF in REST API, how do I get those values?
- How to display Custom Post Type Post based on Tag with Shortcode Parameter?
- Validate custom fields before save using WordPress Rest API
- How can I dynamically add a post to a custom post type which uses a custom field?
- Problem with WordPress query on page using custom fields
- Default sort on admin columns with meta date hides draft posts with empty date value
- Custom Taxonomy terms aren’t getting referenced or saved in Quick Edit or Bulk Edit, only on Single product page?
- Troubles with acf/save_post and WP_Query
- Query custom post type with ACF Date
- custom post type WYSIWG removes paragraphs when displayed
- ACF From & To Date Validations
- Exclude objects from WordPress API based from ACF field using rest_prepare_{$post_type}
- CPT archive admin menu label
- Rewrite Rule for showing Parent/Child Relationship between Two Hierarchical Custom Post Types
- Order Custom Post Type by Custom Field Value
- Lists custom taxonomy terms that has specific custom field value assigned to the term (not post)
- Meta Query posts not showing on ending date of custom field
- How to update post meta on uploaded image from a custom form?
- How to order posts of a custom post type by date DESC in dashboard Admin?
- Adavnced custom fields relationship query plus query inside
- Querying & displaying custom post type into an existent page [closed]
- Custom post type showing same Post on all Pages
- Post loop count is not in order
- How to inherit field value from parent post into in child / sub post
- How can I add a shortcode to query Custom Post Type with ACF in WordPress?
- I am trying to get cutom post cout by month of current taxonmy term
- ACF for custom post type archive pages: which hook to use?
- How to use single.php for creating, reading and editing Custom Posts with ACF
- posttype and custom fields on multisite
- How do I show a link or ‘Read More’ button on a custom field excerpt when it is less than the word limit
- Custom fields not showing in custom post type
- meta query not retrieving posts
- How to display a WordPress Custom Field only on a specific day of the week?
- Advanced custom field – posted fields from custom post type
- delete duplicate meta_value with same post_id
- How to display author details in a custom post type in the wordpress backend?
- Show/hide posts and categories based on user meta
- ACF – Retrieve custom taxonomy from a relationship field
- Custom front-end form for adding post – Category problem
- Set up a WP Cron scheduled event to update calculated ACF field
- Show Post Revisions on front-end
- How to show Custom Post Type – Case Study using Shortcode & ACF
- Add custom post related by custom field to custom post
- Create loop from selected terms in ACF taxonomy field
- Sort custom posts by date and then by taxonomy
- How to set post date in post_type so that it’s same as latest post in category
- Show custom post type event if current day using ACF
- Issue to display Permalink (ACF Relationships in Custom Post Type )
- Compare ACF Date field to today or yesterday
- Filter posts by their related field’s custom field
- If ACF Post Object post has custom taxonomy term…
- Changing default admin column sorting to an ACF Date Picker field
- Taxonomy shows up twice on Custom Post Type
- Create 3 Levels of relations with WordPress
- Wrapping an unknown amount of posts inside separate HTML Containers during WP_Query loop
- Some permalinks on Apache/localhost development setup return 404’s when set to anything other than plain permalinks
- Linking posts together with Advanced Custom Fields “both ways”
- How to get a custom post type archive paged when using a custom field for post sorting?
- save_post affect creation and deletion
- How can I save a Custom Post Title and Slug with a Custom Field?
- Custom Field as Custom Post type element class
- Extracting Post ID and passing through as an attribute in a shortcode
- group posts by month/date ignore years
- How to query posts by meta keys AND under specific category?
- How to display custom post type ordered by a custom field date
- how to load custom single.php?
- Setting a custom $query->query_vars[‘meta_key’] breaks the WordPress menu
- Function that get ACF fields value before saving
- How to query the content of a specific custom post type?
- Custom post type adding additional markup
- Advanced Custom Fields: query posts filtered by multiple field values
- Custom Post-type not returning the right child_of
- Register a title automatically with a relationship field
- How to randomize published date for WordPress custom post type
- Why custom search engine only searches in post titles of custom posts?
- Display ACF object field data using Elementor Custom Query