I found a solution but i’m sure there is a better way.
I add an action on rest_insert_<post_type>
hook
add_action( 'rest_insert_project', 'prefix_update_files_field', 10 , 3 );
function prefix_update_files_field($post, $request, $true){
global $wp_rest_additional_fields;
$my_post_type="project";
$additional_fields = $wp_rest_additional_fields[$my_post_type];
foreach ( $additional_fields as $field_name => $field_options ) {
if ( ! $field_options['update_callback'] ) {
continue;
}
// Don't run the update callbacks if the data wasn't passed in the request.
if ( ! isset($_FILES[ $field_name ] ) ) {
continue;
}
$result = call_user_func( $field_options['update_callback'], $_FILES[ $field_name ], $post, $field_name, $request, $my_post_type );
if ( is_wp_error( $result ) ) {
return $result;
}
}
}
Related Posts:
- How to add custom fields to admin UI and REST API response?
- Custom search with Custom Fields in WP REST API?
- Cannot add custom field to “orderby” parameter in Rest API
- Callback to custom field is not working in WordPress REST API
- filter custom post in rest api with custom function
- Custom REST endpoints for a custom post type with custom fields
- Create custom post with meta field with AJAX and the WordPress REST API
- How to make an API call to a custom post type but filtering by meta value?
- How To Read Read Custom Post Type Data in Headless CMS Mode
- How can I add a meta[] to my custom post type and search by term with the Rest API?
- filter rest api post by a acf filed
- How to properly set a value to meta fields of a custom post type in WP-API/node-wpapi REST API?
- querying to custom field over ACF REST API
- How to Add Custom Fields to a Custom Post Type?
- Do_Shortcode not working for Embed
- Display custom post type and custom fields within a Bootstrap Carousel
- Custom Taxonomy Template Post List with Sort Order
- Display Custom Post Type Fields
- WP Rest API Querying Custom Posts by ACF fields
- How to get dynamically custom post type that are under a certain category
- Using new WP_Query in shortcode in a custom field causes the main post content to not display
- WordPress query by multiple Custom fields and order by date
- Using ‘strtotime’ function to convert a custom-meta-box to a date-stamp
- add_meta_box: Datepicker like the one for postdate?
- Custom field losing p tags on display
- Bulk edit custom excerpt text in WordPress
- Formatting custom meta box date from YYYY/MM/DD to a more readable alternative
- Getting a “Changes you made will be lost” dialog prompt on a custom post type page
- Frontend posting – everything saves other than checkboxes?
- Search Custom Post Type Custom Fields
- Saving repeated option values in a custom query
- handling csv data with a custom post type
- Custom Post Type and API REST is not working
- How to remove slug metabox from custom post type’s page?
- Custom fields in Permalinks?
- query posts and custom post type with meta key
- Problem fields custom date, time, and checkbox
- Sorting custom post type columns with external data and without meta values
- What is the recommended / best way to do this: Event calendar post/type in a block-based theme?
- WordPress Custom Fields Won’t Save
- Getting meta in editor plugin, and event triggering issue
- Found 2 elements with non-unique id (#_ajax_nonce) and (#_wpnonce)
- Store CPT ‘Reviews’ average ratings to a WordPress DB table or to a DB custom table?
- Meta Query Not Returning Output Despite Having Matching Values
- Repeatable Fields Metabox with Textarea (or wp_editor)
- How to use TinyMCE Editor for one of my custom post meta field?
- How to display products name in a non-alphabetical order, in a custom field (taxonomy)?
- Displaying custom field according to date
- filter search custom field query
- Custom fields for custom post type
- Warning: Invalid argument supplied for foreach() [closed]
- Add additional field to custom post_type
- Sorting posts by custom field value in array
- How to conditionally add Custom Post Type to Front Page
- Custom REST endpoint not working to retrieve single posts (“rest_no_route”)
- Displaying custom fields for custom post type generate with Custom Post Type UI Plugin
- Display a post from custom post type only if all the selected taxonomies and custom field value matches the record
- How to handle new post from API request?
- How do I get_the_postID() for a custom post that uses ACF repeater field?
- How to populate a Gravity Forms Custom Post Field (dropdown type) with custom taxonomy terms? [closed]
- Custom post type name and assigning custom taxonomy
- Best way to create a search for custom post type by custom field values
- Building a Portfolio and need some direction
- Need to have an archive widget which organizes and displays a custom post type using a custom date field
- Display Posts Query with IF function
- Excerpt length: get first paragraph
- Custom PT, Taxonomys and wordpress query
- How can i loop through custom post type according to custom meta field?
- How to use get_post_custom_values to return the value of an array
- Problem with date comparison for custom fields
- Creating a custom page post type just like the original “pages” post type using CPT UI
- Using OR relation in meta_query to check for a value before sorting by another
- How to add field to custom post type endpoint
- How can I create a button that when clicked populates a div with a list of foods that are checked as a certain type of ACF?
- Query custom post type and custom field by URL parameters
- Show Post columns to specific users on condition
- Custom post types – meta_query: search lesson which starts sooner
- Saving custom post types post_meta over REST-API fails
- Create Inclusions and exclusions
- Populate custom post type/custom fields from an external database
- Custom Field to post_title
- Automatically convert standard posts with custom fields to custom post types
- Retrieving custom post type fields without a post
- Get month and day from a Date Picker custom field
- custom fields not showing before get_header
- pre_get_posts with multiple post types AND a meta_key
- Search form to find custom meta box generated data
- Custom Info Box at end of posts?
- Display Custom Post if custom field is marked
- predefined custom field on registration page
- Show Custom Post Type taxonomy term that matches custom field
- Query Distinct Taxonomies of Custom Post Type
- loop through custom post-type with two meta_keys
- Allow authors to create article image
- Custom Post Type + Custom Meta Query Not Showing 2012 Posts
- Is it possible to specify a time interval (from, to) in ACF with date picker, or other custom field?
- Display ACF object field data using Elementor Custom Query
- Sortable admin columns ordering from custom fields isn’t combine com search and Dropdown filter
- WordPress custom field sorting, weird behavior: the latest post is at the end
- I want to understand plugin implementation of custom posts / taxonomies / metaboxes