Support

Account

Home Forums Backend Issues (wp-admin) Edit fields from attachment on page edit screen?

Solved

Edit fields from attachment on page edit screen?

  • Hi,

    I have added two fields two attachments (regular text fields).

    What I want is, when I add a featured image to a page, to show the fields from this media library below the image on the edit page screen.

    I already found a way to add/edit text of the featuredimage_metabox, but I’m unsure how to add the custom field editor here. This is the code I’m using:

    /*
     * Customize the Featured Image metabox w/ info-text
     * 
    */ 
    function mim_remove_featuredimage_metabox() {
        remove_meta_box( 'postimagediv', 'post', 'side' );
    }
    add_action( 'admin_head', 'mim_remove_featuredimage_metabox' );
    
    function mim_custom_featuredimage_metabox( $post ) {
    	
    	$thumbnail_id = get_post_meta( $post->ID, '_thumbnail_id', true );
    	
    	echo "Blah blah";
    	echo _wp_post_thumbnail_html( $thumbnail_id, $post->ID );
    	
    }
    function mim_add_featuredimage_metabox() {
    	add_meta_box( 'postimagediv', __( 'Featured Image' ), 'mim_custom_featuredimage_metabox', 'post', 'side', 'default' );
    }
    add_action( 'admin_head', 'mim_add_featuredimage_metabox' );

    Any ideas/pointers?
    Thanks!

  • I don’t really understand what your attempting to do in your code since it is not using ACF. I also don’t think I understand what you’re trying to accomplish.

  • Sorry, reading it back now I agree it isn’t really clear what I’m trying to accomplish 😉

    I have added a two custom fields to attachments (media) using ACF.

    Whenever I choose a featured image in a post, I want the custom fields for this particular attachment to show below the featured image, and save them when saving the post.

  • I found this, looks like what you’re looking for, https://generatewp.com/add-custom-fields-to-featured-image-meta-box/. You’ll need to use the ACF field names where field names are used in the example. Also, you will need to update the field keys. Or, alternately, you might be able to use update_field() instead of update_post_meta(), just make sure you use the field keys when updating ACF field values https://www.advancedcustomfields.com/resources/update_field/

  • Thanks, it took a bit of puzzling but I figured it out using your links.

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

The topic ‘Edit fields from attachment on page edit screen?’ is closed to new replies.