Search
 
SCRIPT & CODE EXAMPLE
 

PHP

wp rest api acf fields

function create_ACF_meta_in_REST() {
    $postypes_to_exclude = ['acf-field-group','acf-field'];
    $extra_postypes_to_include = ["page"];
    $post_types = array_diff(get_post_types(["_builtin" => false], 'names'),$postypes_to_exclude);

    array_push($post_types, $extra_postypes_to_include);

    foreach ($post_types as $post_type) {
        register_rest_field( $post_type, 'ACF', [
            'get_callback'    => 'expose_ACF_fields',
            'schema'          => null,
       ]
     );
    }

}

function expose_ACF_fields( $object ) {
    $ID = $object['id'];
    return get_fields($ID);
}

add_action( 'rest_api_init', 'create_ACF_meta_in_REST' );
Comment

PREVIOUS NEXT
Code Example
Php :: create database in php 
Php :: refresh laravel model 
Php :: laravel with and where 
Php :: create table laravel 
Php :: symfony form get errors 
Php :: html pagination php 
Php :: aws sdk php 
Php :: wp change num words exerpct 
Php :: php strpos 
Php :: mysql Cannot pass parameter 2 by reference 
Php :: php dies while parsing json 
Php :: isset laravel 
Php :: Syntax error or access violation: 1071 Specified key was too long; max key length 
Php :: UUIDs LARAVEL 
Php :: call to a member function get_results() on null 
Php :: php variable as javascript function parameter in echo 
Php :: php url exists valid 
Php :: laravel eloquent duplicate record 
Php :: laravel 8 validation unique 2 columns 
Php :: php remove value from array 
Php :: laravel multiple copy record 
Php :: Hide Add to cart button on specific products 
Php :: return redirect to extranal url in laravel 
Php :: laravel blade if else condition 
Php :: laravel rule unique where 
Php :: Laravel query where and 
Php :: session_regenerate_id 
Php :: how do i know if file is empty in php 
Php :: laravel error messages 
Php :: install execute array in php 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =