Inserting metabox values into the post

In the child theme's function.php I'd extend the media upload form with two fields. These fields contain additional information for every image. And can be inserted when the image will be uploaded.

Now the way back & my problem:
I want to get the values of these extra fields when I use the common 'Add media file'-Button in the backend editor, so like it works with the caption field.

My questtion: Is that possible with coding within the function.php, and how ?

  • Rupok

    Hi bauerxcel-crt,

    Thanks for asking. You said "In the child theme's function.php I'd extend the media upload form with two fields". Can you please share your code so we can get idea regarding how it was constructed?

    I want to get the values of these extra fields when I use the common 'Add media file'-Button in the backend editor, so like it works with the caption field.

    Again, If you provide your code, that will give us idea regarding how to get the values of those extra fields. And I can tell you best if this will be possible for backend editor media button, if I can get to see your code.

    Can you please share your code? I'll try to find a fix after checking your code. I'm looking forward to hear from you and resolve this issue as soon as possible.

    Have a nice day. Cheers!
    Rupok

  • bauerxcel-crt
    function crt_attachment_field_credit( $form_fields, $post ) {
    	$form_fields['crt-photographer-name'] = array(
    		'label' => 'Photographer Name',
    		'input' => 'text',
    		'value' => get_post_meta( $post->ID, 'crt_photographer_name', true ),
    		'helps' => 'If provided, photo credit will be displayed',
    	);

    This is the code for one input -field, nothing special. And storing the value in post_meta-table is no problem as well.

    So, what I want is, and this without touching any wp-core-files, to insert the value in the text-editor-field.
    It would be a handy workflow, when the editor would have the option to insert this, when he/she insert the image itself into the content.

  • bauerxcel-crt

    The button in backend <- click this button
    The input field(s) <-- see this fields in backend
    <-- fill out the fields
    then <ok>
    [caption id="attachment_4580" align="alignleft" width="400"]<img src="/wp-content/uploads/2016/09/monkey-987.jpg" alt="This is the alt text" width="400" height="300" class="size-full wp-image-4580" /> This is the caption[/caption]
    The result, without my field.
    And I want to have a result like this:
    [caption id="attachment_4580" align="alignleft" width="400"]<img src="/wp-content/uploads/2016/09/monkey-987.jpg" alt="This is the alt text" width="400" height="300" class="size-full wp-image-4580" /> This is the caption<br /> (The Photographer's name)[/caption]

  • Panos

    Hi bauerxcel-crt ,

    Did you have the chance to checkout the plugin my colleague Rupok suggested on chat?

    Could you please provide more information so I can get a picture of what needs to be done?

    Of what I understand you want to add some extra fields in the Media uploader and then to fetch the information inserted there.

    Please let me know if I understood wrong here and how the plugin worked for you :slight_smile:

    Thanks!
    Panos

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.