Support

Account

Forum Replies Created

  • 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' );
  • While “Media” is definitely of post type “attachment” there is no route at /wp-json/wp/v2/attachment/

    When submitting a GET to /wp-json/wp/v2/media/, an empty array of acf is shown for each object. Even with fields populated, no data is returned. In addition, a POST to a specific media item at /wp-json/wp/v2/media/<id> to update a custom field does not work in the same way it does for other post types/custom post types.

    Is there an alternate method available of updating data in ACF fields groups shown on media/attachments?

  • It does! I tracked down that guide and it definitely breaks down the display well, but I’m now wondering what the best way is to hook into WordPress’s default display of images. I’ve modified the way the caption shortcode works to change that output before, but I’ll need this to spit out available photo credits for images with or without captions, so messing with caption shortcode won’t help.

Viewing 3 posts - 1 through 3 (of 3 total)