Support

Account

Home Forums General Issues Including ACF data for media Reply To: Including ACF data for media

  • Fair enough, @hube2!

    We were able to bypass this issue by manually exposing the field:

    function our_expose_attribution() {
    	// Field name to register.
    	$field = 'attribution';
    	register_rest_field(
    		'attachment',
    		$field,
    		array(
    			'get_callback' => function ( $object ) use ( $field ) {
    				// Get field as single value from post meta.
    				return get_post_meta( $object['id'], $field, true );
    			},
    			'update_callback' => function ( $value, $object ) use ( $field ) {
    				// Update the field/meta value.
    				update_post_meta( $object->ID, $field, $value );
    			},
    			'schema' => array(
    				'type' => 'string',
    				'arg_options' => array(
    					'sanitize_callback' => function ( $value ) {
    						// Make the value safe for storage.
    						return sanitize_text_field( $value );
    					},
    					'validate_callback' => function ( $value ) {
    						// Validate
    						return is_string( $value );
    					},
    				),
    			),
    		)
    	);
    }
    add_action( 'rest_api_init', 'our_expose_attribution' );