【问题标题】:How to change the form enctype for custom post type in Wordpress?如何在 Wordpress 中更改自定义帖子类型的表单 enctype?
【发布时间】:2012-03-30 16:41:23
【问题描述】:

我正在创建自定义帖子类型的音乐。

function layzend_admin_music_init() {
  add_meta_box("layzend_music_information-meta", "Information", "layzend_music_information", "music", "normal", "low");
}

function layzend_music_information() {
    ?>
    <p>
        <label for="layzend_music_url">URL</label>
        <input type="file" id="layzend_music_url" name="layzend_music_url" />
    </p>
    <?php
}

此文件字段需要表单 enctype 为 multipart/form data 如何更改自定义帖子类型的默认表单 enctype?

【问题讨论】:

    标签: wordpress


    【解决方案1】:

    试试这个:

    add_action('post_edit_form_tag', 'add_post_enctype');
    
    function add_post_enctype() {
        echo ' enctype="multipart/form-data"';
    }
    

    更多info in the Codex.

    这对你有用吗?

    【讨论】:

    • 完美的解决方案,允许使用像 save_post 这样的钩子访问 $_FILES。
    猜你喜欢
    • 2017-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多