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

Advanced custom field – posted fields from custom post type

You can find the Advanced Custom Fields fields which you added in the $_POST array under the ‘fields‘ key. Use ACF’s get_field_object() function to get the key of your field you added.

So if you named your field ‘nr_available’, you have to find its key to be able to find this field in the $_POST object (so you can fetch $_POST[‘fieldKey’]).

Check the following code:

function update_course($course_id)
{
    $nr_available = 0;
    $nr_registered = 0;

    $field1 = get_field_object('nr_available');
    $nr_available_key = $field1['key'];

    $field2 = get_field_object('nr_registered');
    $nr_registered_key = $field2['key'];

    // loop the $_POST['fields'] which contains all the Advanced Custom Fields fields which you added to the post you are editing
    foreach ($_POST['fields'] as $k=>$v)
    {
        // $k are the custom fields keys
        // $v are the custom fields values

        if ($k == $nr_available_key){
            $nr_available = $v;
        }
        if ($k == $nr_registered_key){
            $nr_registered = $v;
        }
     }

     // Do your checks after you get the values
     if ( ($nr_available > $nr_registered) || $nr_available <= 0 )
     {
        // Bad
        return;
     }
}
add_action( 'edit_post' , 'update_course');

Related Posts:

  1. ACF Upload Image in repeater from front-end with custom form? – add_post_meta()
  2. Custom fields (wp_post_meta) vs Custom Table for large amount of data
  3. Batch Extract Date from post title and put into ACF custom field
  4. Linking posts together with Advanced Custom Fields “both ways”
  5. Query all posts where a meta key does not exist
  6. Can the Next/Prev Post links be ordered by menu order or by a meta key?
  7. what is the correct way to compare dates in a WP query_posts meta_query
  8. Advanced search form with filters for custom taxonomies and custom fields
  9. Meta query with boolean true/false value
  10. Filter by custom field in custom post type on admin page
  11. Getting custom taxonomy from custom post type
  12. Media library – Limit images to custom post type
  13. Get post with multiple meta keys and value
  14. Correctly delete posts with meta and attachments [duplicate]
  15. Filter next_post_link() and previous_post_link() by meta_key?
  16. importing third party json feed as custom post type [closed]
  17. Storing revisions of metadata for custom post type
  18. Custom field values deleted when trashing custom post type
  19. how to get posts by custom post type then display Custom fields?
  20. How to get all custom fields of any post type
  21. Update CPT meta data using REST API
  22. Admin Area Custom Type Search By Meta Fields Without Title & Content
  23. Echo all meta keys of a custom-post TYPE
  24. Custom Post type – how to get checkbox to update meta field to null
  25. How can I filter posts by post_parent in the admin?
  26. How do I Paginate Search Results for Custom Post Types?
  27. Filtering a WP_Query meta_query by numeric values isn’t working
  28. Populate a ACF Select Dropdown from Custom Post Type
  29. Automatically fill custom field value on post publish/update
  30. Ordering posts having multiple post-meta date fields
  31. Custom Post Type with Input fields to seperate table on database.
  32. How do I remove all the metaboxes for a custom post type?
  33. Custom Queries: Joining On Meta Values From Two Custom Post Types
  34. Gutenberg how to make attribute to save to meta
  35. Filter a custom field based on selection of another custom field (ACF) [closed]
  36. How to programmatically create a connection with [Plugin: Posts 2 Posts] on cpt publish?
  37. Post metadata deletes itself
  38. How to create a mini directory in WordPress?
  39. How Can I save multiple records in same meta key?
  40. Get all posts from custom post type and insert in select input as metabox
  41. Make permalinks based on an ACF-field
  42. Detect meta value changes when post is updated (post_updated)
  43. Search everything (posts, pages, tags, cpt, meta)
  44. ACF Relationships in Custom Post Type Permalink
  45. WP Rest API Querying Custom Posts by ACF fields
  46. How to sort a table of custom posts by column containing custom field
  47. WordPress Search documentation: how to improve search query using taxonomy terms, custom meta fields?
  48. Permalinks using event date (year & month) instead of publication date
  49. Custom Post Type: Set post_title equal to a custom post type field
  50. I can’t set meta_key in my custom post type query
  51. Grossly inefficient wordpress loops!
  52. Meta Query “IN” doesn’t work with ACF checkbox filter
  53. Compare 3 custom fields and sort by oldest
  54. Retrieve a specific field from taxonomy term through advanced custom fields [closed]
  55. How Do I Use WP_Query to Run This Database Query as Search Result?
  56. List events by month
  57. WordPress Admin Panel search posts with custom post meta values along with title
  58. Creating a custom post type upon registration
  59. How to Update post status using meta data in Custom post TYpe
  60. Use Custom Post Type as Custom Field
  61. Count custom post types with a specific meta value
  62. Rest Api v2 orderby meta_key in custom post type
  63. Query by 2 values of a repeater ACF field
  64. bulk Update post_meta with default values
  65. Reason action hook won’t work with update_post_meta from frontend form? Alternative?
  66. Insert slider (Custom Post Type) into pages
  67. Can’t sort order of wp_query with 2 meta keys
  68. Showing Meta Data for Custom Post Types?
  69. How to get source of custom meta image?
  70. get terms that have post with custom post type between 2 values
  71. Having trouble with custom post type / meta box
  72. Query for posts from any post type but only add instock products
  73. How can I include meta box content when searching?
  74. update a post meta from a single table cell TablePress
  75. update custom post type meta from a shortcode
  76. Custom Meta Boxes – Nonce Issue – Move to trash issue
  77. How to set custom post type as post title to avoid ‘Auto Draft’
  78. Displaying Meta Box Image
  79. Custom post type category not displaying in custom post type
  80. How to make custom post meta wp_editor translatable?
  81. Pull image from ACF field in a Custom Post Type
  82. Archive filter disappears on no results?
  83. Automatically adding meta data to posts or multiple query help
  84. Query current and future events, ordered by begin date
  85. How to keep a check box in custom meta box for custom post type checked by default for add new post?
  86. How to add multiple featured image in meta box in post editor?
  87. Show metabox in custom-post-template depending on taxonomy term?
  88. Show ACF field from custom taxonomy and display on the single template
  89. Change message given when deleting post from custom post type
  90. Building an Advanced Search (text, tags, category, custom fields) – Getting the wrong SQL query
  91. Display posts if a custom field value is equal to another custom field value
  92. Linking three taxonomies with ACF
  93. update_post_meta() whenever custom post type is updated
  94. Formatting custom meta box date from YYYY/MM/DD to a more readable alternative
  95. Trigger “unsaved changes” dialog for custom post meta changes
  96. Using date stored as custom field to filter posts displayed in admin
  97. Conditionally Query Custom Post Types by Post Meta for Blog Home Page?
  98. Get Custom Field Values by Another Custom Field in WordPress
  99. Displaying custom posts only if custom meta box’s date is not expired
  100. WordPress custom post type archive with description
Categories custom-post-types Tags advanced-custom-fields, custom-post-types, post-meta
register_sidebar_widget is deprecated since version 2.8
Ansible stuck on gathering facts

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