Wordpress媒体上传额外字段

时间:2010-11-19 13:43:55

标签: wordpress wordpress-plugin wordpress-theming

如何在wordpress媒体面板中创建另一个字段?

目前,您拥有所有必要的字段,但我需要添加一个额外字段来捕获一些额外的细节。

我正在使用寻找一组字段的Flash播放器,理想情况下我想要一个名为video_url的字段

有什么想法吗?

2 个答案:

答案 0 :(得分:1)

我不确定如何在媒体面板中添加额外字段...但您可以使用Magic Field创建媒体上传器和额外字段,其中包含您的额外详细信息...了解有关Magic Field的更多信息插件在这里:http://wordpress.org/extend/plugins/magic-fields/

答案 1 :(得分:0)

想出了这个解决方案。

function rt_image_attachment_fields_to_edit($form_fields, $post) {
    // $form_fields is a an array of fields to include in the attachment form
    // $post is nothing but attachment record in the database
    //     $post->post_type == 'attachment'
    // attachments are considered as posts in WordPress. So value of post_type in wp_posts table will be attachment
    // now add our custom field to the $form_fields array
    // input type="text" name/id="attachments[$attachment->ID][custom1]"
    $form_fields["rt-image-link"] = array(
        "label" => __("Video URL"),
        "input" => "text", // this is default if "input" is omitted
        "value" => get_post_meta($post->ID, "_rt-image-link", true),
            "helps" => __(""),
    );

    $form_fields["rt-video-link"] = array(
        "label" => __("Library Ref"),
        "input" => "text", // this is default if "input" is omitted
        "value" => get_post_meta($post->ID, "_rt-video-link", true),
            "helps" => __(""),
    );
    return $form_fields;
}
// now attach our function to the hook
add_filter("attachment_fields_to_edit", "rt_image_attachment_fields_to_edit", null, 2);

function rt_image_attachment_fields_to_save($post, $attachment) {
    // $attachment part of the form $_POST ($_POST[attachments][postID])
    // $post['post_type'] == 'attachment'
    if( isset($attachment['rt-image-link']) ){
        // update_post_meta(postID, meta_key, meta_value);
        update_post_meta($post['ID'], '_rt-image-link', $attachment['rt-image-link']);
    }

    if( isset($attachment['rt-video-link']) ){
        // update_post_meta(postID, meta_key, meta_value);
        update_post_meta($post['ID'], '_rt-video-link', $attachment['rt-video-link']);
    }
    return $post;
}
// now attach our function to the hook.
add_filter("attachment_fields_to_save", "rt_image_attachment_fields_to_save", null , 2);