Php 保存元数据框问题

Php 保存元数据框问题,php,wordpress,save,Php,Wordpress,Save,我在我的wordpress保存元数据框数据时遇到了问题,我使用了一些教程,但它们对我没有帮助,我搜索了很多,但没有任何用处 还要告诉我元数据保存在哪里,我的意思是在哪个表中 我给你看我的代码 Function.php 这是添加元框:: <?php function downlaod_meta(){ add_meta_box('download_id','Download Meta Box','ct_downlaod_meta','post','normal','high'); }

我在我的wordpress保存元数据框数据时遇到了问题,我使用了一些教程,但它们对我没有帮助,我搜索了很多,但没有任何用处

还要告诉我元数据保存在哪里,我的意思是在哪个表中

我给你看我的代码

Function.php

这是添加元框::

<?php
function downlaod_meta(){
    add_meta_box('download_id','Download Meta Box','ct_downlaod_meta','post','normal','high');
}
add_action('add_meta_boxes','downlaod_meta');

function ct_downlaod_meta($post){
    $value = get_post_custom($post->ID);

    $url = isset( $value['txt_meta_url'] ) ? esc_attr( $value['txt_meta_url'][0] ) : ''; 
    $title = isset( $value['txt_meta_title'] ) ? esc_attr( $value['txt_meta_title'][0] ) : '';
    $size = isset( $value['txt_meta_size'] ) ? esc_attr( $value['txt_meta_size'][0] ) : '';
    $author = isset( $value['opt_meta_author'] ) ? esc_attr( $value['opt_meta_author'][0] ) : '';
    $editor = isset( $value['txt_meta_editor'] ) ? esc_attr( $value['txt_meta_editor'][0] ) : ''; 

    // Nonce to verify intention later  
    wp_nonce_field( 'save_download_meta', 'download_nonce' ); 

?>
    <table width="100%" border="0" cellspacing="6" cellpadding="0">
        <tr>
            <td>
                <label><strong>Download URL</strong></label>
            </td>
            <td>
                <input type="text" name="txt_meta_url" id="txt_meta_url" size="80" value="<?php echo $url ?>" />
            </td>
        </tr>
        <tr>
            <td>
                <label><strong>Download Title</strong></label>
            </td>
            <td>
                <input type="text" name="txt_meta_title" id="txt_meta_title" size="80" value="<?php echo $title ?>" />
            </td>
        </tr>
        <tr>
            <td>
                <label><strong>Download Size</strong></label>
            </td>
            <td>
                <input type="text" name="txt_meta_size" id="txt_meta_size" size="80" value="<?php echo $size ?>" />
            </td>
        </tr>
        <tr>
            <td>
                <label><strong>Author</strong></label>
            </td>
            <td>
                <select multiple="multiple" name="opt_meta_author" id="opt_meta_author">
                    <option value="Amjad" <?php selected( $author, 'Amjad' ); ?>>Amjad</option>
                </select>
                <br />
        <span style="font-size:12px; font-style:italic; color:#b1b1b1;">Hold down the Ctrl (windows) / Command (Mac) button to select multiple options.</span>
            </td>
        </tr>
        <tr>
            <td>
                <label><strong>Editor</strong></label>
            </td>
            <td>
                <select name="opt_meta_editor" id="opt_meta_editor" style="width:70%;">
                    <option>:.. Select Editor ..:</option>
            <?php
                $args = array(
                    'orderby' => 'display_name',
                    'order' => 'ASC'
                );

                $user_query = new WP_User_Query($args);

                foreach ( $user_query->results as $user ) {
            ?>
                    <option value="<?php echo $user->display_name ?>" <?php selected( $editor, $user->display_name ); ?>>
                        <?php echo $user->display_name ?>
                    </option>
            <?php
                }
            ?>
                </select>
            </td>
        </tr>
    </table>

<?php
}
?>

下载URL
我找到了解决办法

functions.php

把肉放进盒子里

<?php

function downlaod_meta($post){
    add_meta_box('download_id','Download Details','ct_downlaod_meta','post','normal','high');
}
add_action('add_meta_boxes','downlaod_meta');

function ct_downlaod_meta($post){

    $txt_meta_url = get_post_meta($post->ID, 'txt_meta_url', true);
    $txt_meta_title = get_post_meta($post->ID, 'txt_meta_title', true);
    $txt_meta_size = get_post_meta($post->ID, 'txt_meta_size', true);
    $opt_meta_author = get_post_meta($post->ID, 'opt_meta_author', true);
    $opt_meta_editor = get_post_meta($post->ID, 'opt_meta_editor', true);

?>
    <table width="100%" border="0" cellspacing="6" cellpadding="0">
        <tr>
            <td>
                <label><strong>Download URL</strong></label>
            </td>
            <td>
                <input type="text" name="txt_meta_url" id="txt_meta_url" size="80" value="<?php echo $txt_meta_url; ?>" />

            </td>
        </tr>
        <tr>
            <td>
                <label><strong>Download Title</strong></label>
            </td>
            <td>
                <input type="text" name="txt_meta_title" id="txt_meta_title" size="80" value="<?php echo $txt_meta_title ?>" />
            </td>
        </tr>
        <tr>
            <td>
                <label><strong>Download Size</strong></label>
            </td>
            <td>
                <input type="text" name="txt_meta_size" id="txt_meta_size" size="80" value="<?php echo $txt_meta_size ?>" />
            </td>
        </tr>
        <tr>
            <td>
                <label><strong>Author</strong></label>
            </td>
            <td>
                <select multiple="multiple" name="opt_meta_author" id="opt_meta_author">
                <?php
                    $authors = new WP_Query(array( 'post_type' => 'author', 'orderby' => 'title', 'order' => 'ASC' ));

                    while($authors->have_posts()) :
                            $authors->the_post();
                ?>
                    <option value="<?php echo the_ID() ?>" <?php selected( $opt_meta_author, the_ID() ); ?>>
                        <?php echo the_title(); ?>
                    </option>
                <?php
                    endwhile;
                ?>
                </select>
                <br />
        <span style="font-size:12px; font-style:italic; color:#b1b1b1;">Hold down the Ctrl (windows) / Command (Mac) button to select multiple options.</span>
            </td>
        </tr>
        <tr>
            <td>
                <label><strong>Editor</strong></label>
            </td>
            <td>
                <select name="opt_meta_editor" id="opt_meta_editor" style="width:70%;">
                    <option>Select Editor</option>
            <?php
                $args = array(
                    'orderby' => 'display_name',
                    'order' => 'ASC'
                );

                $user_query = new WP_User_Query($args);

                foreach ( $user_query->results as $user ) {
            ?>
                    <option value="<?php echo $user->ID ?>" <?php selected( $opt_meta_editor, $user->ID ); ?>>
                        <?php echo $user->display_name ?>
                    </option>
            <?php
                }
            ?>
                </select>
            </td>
        </tr>
    </table>

<?php
}
?>

下载URL
<?php

function downlaod_meta($post){
    add_meta_box('download_id','Download Details','ct_downlaod_meta','post','normal','high');
}
add_action('add_meta_boxes','downlaod_meta');

function ct_downlaod_meta($post){

    $txt_meta_url = get_post_meta($post->ID, 'txt_meta_url', true);
    $txt_meta_title = get_post_meta($post->ID, 'txt_meta_title', true);
    $txt_meta_size = get_post_meta($post->ID, 'txt_meta_size', true);
    $opt_meta_author = get_post_meta($post->ID, 'opt_meta_author', true);
    $opt_meta_editor = get_post_meta($post->ID, 'opt_meta_editor', true);

?>
    <table width="100%" border="0" cellspacing="6" cellpadding="0">
        <tr>
            <td>
                <label><strong>Download URL</strong></label>
            </td>
            <td>
                <input type="text" name="txt_meta_url" id="txt_meta_url" size="80" value="<?php echo $txt_meta_url; ?>" />

            </td>
        </tr>
        <tr>
            <td>
                <label><strong>Download Title</strong></label>
            </td>
            <td>
                <input type="text" name="txt_meta_title" id="txt_meta_title" size="80" value="<?php echo $txt_meta_title ?>" />
            </td>
        </tr>
        <tr>
            <td>
                <label><strong>Download Size</strong></label>
            </td>
            <td>
                <input type="text" name="txt_meta_size" id="txt_meta_size" size="80" value="<?php echo $txt_meta_size ?>" />
            </td>
        </tr>
        <tr>
            <td>
                <label><strong>Author</strong></label>
            </td>
            <td>
                <select multiple="multiple" name="opt_meta_author" id="opt_meta_author">
                <?php
                    $authors = new WP_Query(array( 'post_type' => 'author', 'orderby' => 'title', 'order' => 'ASC' ));

                    while($authors->have_posts()) :
                            $authors->the_post();
                ?>
                    <option value="<?php echo the_ID() ?>" <?php selected( $opt_meta_author, the_ID() ); ?>>
                        <?php echo the_title(); ?>
                    </option>
                <?php
                    endwhile;
                ?>
                </select>
                <br />
        <span style="font-size:12px; font-style:italic; color:#b1b1b1;">Hold down the Ctrl (windows) / Command (Mac) button to select multiple options.</span>
            </td>
        </tr>
        <tr>
            <td>
                <label><strong>Editor</strong></label>
            </td>
            <td>
                <select name="opt_meta_editor" id="opt_meta_editor" style="width:70%;">
                    <option>Select Editor</option>
            <?php
                $args = array(
                    'orderby' => 'display_name',
                    'order' => 'ASC'
                );

                $user_query = new WP_User_Query($args);

                foreach ( $user_query->results as $user ) {
            ?>
                    <option value="<?php echo $user->ID ?>" <?php selected( $opt_meta_editor, $user->ID ); ?>>
                        <?php echo $user->display_name ?>
                    </option>
            <?php
                }
            ?>
                </select>
            </td>
        </tr>
    </table>

<?php
}
?>
<?php
add_action('save_post','save_download_meta_data');
function save_download_meta_data(){
    global $post;

    $txt_meta_url = $_POST['txt_meta_url'];
    $txt_meta_title = $_POST['txt_meta_title'];
    $txt_meta_size = $_POST['txt_meta_size'];
    $opt_meta_editor = $_POST['opt_meta_editor'];

    update_post_meta( $post->ID, 'txt_meta_url', $txt_meta_url);
    update_post_meta( $post->ID, 'txt_meta_title', $txt_meta_title);
    update_post_meta( $post->ID, 'txt_meta_size', $txt_meta_size);
    update_post_meta( $post->ID, 'opt_meta_editor', $opt_meta_editor);
}
?>