WP – ADDING CUSTOM FIELDS (ACF) TO REST API Posted on September 2, 2020 by CG Team //====================================================================================================== /** * ADDING CUSTOM FIELDS TO REST */ function acf_custom_rest() { register_rest_field('listing', 'titlePrimo', array( 'get_callback' => function() { $titlePrimo = get_field('subtitle_primo'); return $titlePrimo; } )); register_rest_field('listing', 'titleSecondo', array( 'get_callback' => function() { $titleSecondo = get_field('subtitle_secondo'); return $titleSecondo; } )); register_rest_field('listing', 'titleTerzo', array( 'get_callback' => function() { $titleTerzo = get_field('subtitle_terzo'); return $titleTerzo; } )); } add_action('rest_api_init', 'acf_custom_rest'); // FOLLOWING NOT WORKING WITH CPT NAME, BUT WORK WHEN POST IS USED WHY? function listing_custom_rest() { register_rest_field('listings', 'authorName', array( 'get_callback' => function() {return get_the_author();} )); } add_action('rest_api_init', 'listing_custom_rest'); //======================================================================================================