Support Forum ยป User Profile

Forum Replies Created

Viewing 1 post (of 1 total)
  • Author
    Posts
  • in reply to: rwmb_{$field_id}_after_save_field for Image (multiple) #48845

    If anyone else would like to update the title & alt text from a dashed/underscored file name for an Image field with multiple images, this worked for me (in a class) pulled together from a few different examples:

    
    add_action( 'rwmb_my_image_field_name_after_save_field', array( $this, 'image_title_alt' ), 10, 5 );
    public function image_title_alt( $null, $field, $new, $old, $object_id ) {
    	$images = rwmb_meta( 'my_image_field_name', array(), $object_id );
    	foreach ( $images as $image ) {
    		$title = $image['title'];
    		$title = str_replace( array( '-', '_' ), ' ', $title );
    		$title = ucwords( strtolower( $title ) );
    		update_post_meta( $image['ID'], '_wp_attachment_image_alt', $title );
    		wp_update_post(
    			array(
    				'ID'         => $image['ID'],
    				'post_title' => $title,
    			)
    		);
    	}
    }
    

    Cheers.

Viewing 1 post (of 1 total)