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' );
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.