Support

Account

Home Forums Front-end Issues Display ACF Taxonomy fields by id custom-post-type in a React App with Rest API

Unread

Display ACF Taxonomy fields by id custom-post-type in a React App with Rest API

  • Hello,
    i hope if some of you could help me

    i Have a custom post type (project)
    each ‘project’ has a custom taxomony (area_project)
    this taxonomy has a ACF field ‘color-picker'(colore)

    how can i display this field (colore) in a react map?

    in function.php i’m trying something with register_rest_field, but i can’t connect the taxonomy with the post id
    the following code return my only the ACF fields of the post , not the field in taxonomy connected to the post

    
    function register_rest_project_fields(){
        register_rest_field(
      		[ 'post', 'page', 'project', 'area_project' ], // add post types here
      		'acf_fields', // name of the field
      		array(
      			'get_callback'    => 'get_acf_fields_for_api',
      			'update_callback' => null,
      			'schema'          => null,
      		)
      	);
    }
    function get_acf_fields_for_api( $object, $field_name, $request ) {
    	$data = get_fields( get_the_ID() );
    	return $data ?: false;
    }
    add_action('rest_api_init', 'register_rest_project_fields' );
    

    Some of you have some solution?
    Thanks in advance

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.