• I am trying to get the attachment ID to show in a custom field on the media page within WordPress. I have the custom field showing fine with everything but the attachments id. I have tried everything I can think of, any help would be greatly appreciated.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Brandon_Orndorff

    (@brandon_orndorff)

    Ok this is where I am right now:

    I have the Attachment ID showing on the Media -> Edit Media Page using $_REQUEST[‘attachment_id’];

    However the field shows up blank on the Media Library page within a post (which is where the id really needs to be seen)

    Thread Starter Brandon_Orndorff

    (@brandon_orndorff)

    In case anyone wants to look at the code itself here it is:

    function my_image_attachment_fields_to_edit($form_fields, $post) {
    
    	$form_fields["dl_page_media_field"] = array(
    		"label" => __("Download Page URL"),
    		"input" => "text", // this is default if "input" is omitted
    		"value" => get_post_meta($post->ID, "_dl_page_media_field", true)
    	);
    
    	$form_fields["dl_page_media_field"]["label"] = __("Download Page URL");
    	$form_fields["dl_page_media_field"]["input"] = "text";
    
    //DISPLAY DOWNLOAD PAGE URL WITH FILE TITLE AT END
    global $post;
    global $wpdb;
    
    //FIND ATTACHMENT ID
    $attachmid = $_REQUEST['attachment_id'];
    //END FIND ATTACHMENT ID
    
    	$form_fields["dl_page_media_field"]["value"] = get_site_url()."/file-download-page/?download=$attachmid";
    	return $form_fields;
    }
    
    // attach our function to the correct hook
    add_filter("attachment_fields_to_edit", "my_image_attachment_fields_to_edit", null, 2);

    Thread Starter Brandon_Orndorff

    (@brandon_orndorff)

    Sorry about all the posts, I just want to keep updating with current place I am periodically when I make changes. The following is the cleaned up code (since the code above has a lot of fluff from trying things)

    function dlp_add_custom_fields($form_fields, $post) {
    
    	$attachmid = $_REQUEST['attachment_id'];
    
    	$form_fields["dl_page_media_field"] = array(
    		"label" => __("Download Page URL"),
    		"input" => "text",
    		"value" => get_site_url()."/file-download-page/?download=$attachmid",
    		"helps" => __("Shows below new field"),
    ????);
    	return $form_fields;
    }
    add_filter("attachment_fields_to_edit", "dlp_add_custom_fields", null, 2);
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Get Attachment ID within Media Page Custom Field’ is closed to new replies.