Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

Batch Extract Date from post title and put into ACF custom field

OK, so here’s the function that should do the trick:

function modify_events_to_use_new_field() {
    $events = get_posts( array(
        'post_type' => 'event',
        'post_status' => 'any',
        'posts_per_page' => -1
    ) );

    foreach ( $events as $event ) {
        if ( preg_match('@^(.*) - ([^-]*)$@', $event->post_title, $matches) ) { 
            // you'll have to modify the POST_META_KEY to the real name of your custom field
            update_post_meta( $event->ID, '<POST_META_KEY>', date('Ymd', strtotime($matches[2]) ) );
        }
    }
}

Now you have to change the name of custom field in there and run that function.

Related Posts:

  1. ACF Upload Image in repeater from front-end with custom form? – add_post_meta()
  2. WordPress Orderby Numeric Value Not Working
  3. Show the same Article Available in Other Categories
  4. Post image in WordPress not appearing on home page
  5. Update Post Meta for a logged in user
  6. Two Custom Post Types Many to Many Relationship
  7. Update postmeta Parent when post_status child change
  8. Custom fields (wp_post_meta) vs Custom Table for large amount of data
  9. Advanced custom field – posted fields from custom post type
  10. Get_post_custom not fetching value from array wordpress
  11. Add a form in every post and save data in post meta
  12. SELECT custom post type and its meta in SQL
  13. Save data is post using php front end
  14. How to display posts with plugin (advanced custom fields) field groups?
  15. WordPress – display relationship between blog posts and custom posts
  16. Show posts from WP Custom Post Type selected from a field in a metabox
  17. Adding specific custom fields (images) to post excerpt
  18. How to properly get the wp_postmeta.meta_value of a custom post type in specifics?
  19. Linking posts together with Advanced Custom Fields “both ways”
  20. update a posts of other custom post type
  21. Edit post meta direct from post.php?
  22. How to create content automatically when a post is published?
  23. Display a post count from a custom metabox selection
  24. Top 30 Songs using Custom Post Type
  25. Styling first post using Advanced Custom Fields
  26. Automatically add custom taxonomy when meta value gets to a set number or beyond
  27. I am having a problem with fetching product data in the Gutenberg block editor
  28. How to automatically update ACF field value every year?
  29. How to check if user meta field is empty in conditional else statement
  30. Display only one post each WEEK
  31. How to set YouTube video as featured image?
  32. List children on child post
  33. How can I dynamically add a post to a custom post type which uses a custom field?
  34. Notice: Undefined index: error and understanding wordpress
  35. Problem with WordPress query on page using custom fields
  36. Restrict custom post type from appearing with ?post_types=
  37. the_content() not outputting anything (Advanced Custom Fields)
  38. Show custom post type filtered by category
  39. Custom Post Types. Are there any disadvantages/advantages in using a plugin to develop them?
  40. create parent post using wp_insert_post
  41. Turn on and off custom post type from admin?
  42. Missing Posts in Custom Taxonomy List
  43. Get posts between custom dates
  44. Display random posts, but omit the post it is on?
  45. How do I do this with WordPress? Taxonomies?
  46. Disable block with taxonomies at post page
  47. How to implement a Google map store locator
  48. I would like to have different styles for my posts based on the content of each post
  49. How can i add thumbnails images to particular post (using code not admin pannel) in wordpress
  50. Showing posts from different categories and from custom post type
  51. Get latest 3 posts from multiple CPT in one query
  52. Deleting Custom Posts & Meta Data on Uninstall
  53. Widget: Custom Post Type Post Listing Dropdown on Admin Side
  54. Allow non-logged in users to see a future post after clicking on a list of future posts
  55. Which post does a taxonomy term belongs to?
  56. List custom taxonomy specific to one custom post type
  57. How to add a custom-post-type post within another custom-post-type post edit screen using AJAX?
  58. Meta query for custom post type ignored in main query
  59. Changing custom type name hides the posts
  60. How do I create an archive page as a including metadata?
  61. Display Ad on Specific Categories
  62. How to add a post slug to a url?
  63. Add custom ID to CPT posts only create not update
  64. Hiding posts by other users and non-logged in
  65. Custom Taxonomy terms aren’t getting referenced or saved in Quick Edit or Bulk Edit, only on Single product page?
  66. WP_Query to select custom post type with Advanced Custom Fields (ACF) date
  67. changing meta value and meta key of price field
  68. Posting to a Custom Post Type from front end – user generated content
  69. Bulk Update Custom Fields for Custom Post Types
  70. ACF Field on CPT Slug
  71. Matching Chapters to a Custom posts [closed]
  72. Getting meta in editor plugin, and event triggering issue
  73. Add custom field to Posts and sort by it
  74. How to duplicate entire custom post type
  75. Add custom post type settings to wordress default posts
  76. WP_Query order by custom field, then randomly order some of results
  77. A better way to add a meta box to custom post types
  78. Cluster CPT posts to users based on ACF value from their profile on dashboard
  79. Restrict Access to Posts based on Custom User and Post Meta Data
  80. ACF Values Don’t Show After Import Unless I Edit/Update Post
  81. Get related posts of child term of custom post type
  82. Problem with displaying posts in the CPT category
  83. get_post_meta not working on publishing
  84. Should wp_postmeta meta_key always be unique for a given post_id?
  85. Troubles with acf/save_post and WP_Query
  86. Query custom post type with ACF Date
  87. JS innerhtml changing style when using AJAX
  88. custom post type WYSIWG removes paragraphs when displayed
  89. Stuck in Order by more then one
  90. Custom Post Type + ACF and performance [closed]
  91. Show titles, date of all posts on single category page
  92. how can I register a post_meta field in an existing CPT and then call it again with get_post_custom()?
  93. get_post_meta returning no value in custom post type alert email
  94. Meta Query Not Returning Output Despite Having Matching Values
  95. Side effects of Script and Iframe in post
  96. post meta parameter in post custom-post-type endpoint with restapi
  97. ACF From & To Date Validations
  98. How do I set all of a particular post meta to a value within the custom post type I’m in?
  99. Using advanced custom fields from one custom post type in another custom post type / using nested shortcodes
  100. How to change the post type a theme shows by default?
Categories custom-post-types Tags advanced-custom-fields, custom-post-types, post-meta, posts
Custom post type suddenly stoped working after WordPress 5 update
Hide prices from certain category in woocommerce

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress