Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 多选值保存问题_Php_Wordpress_Save_Meta - Fatal编程技术网

Php 多选值保存问题

Php 多选值保存问题,php,wordpress,save,meta,Php,Wordpress,Save,Meta,我制作了元框,在这个框中,我用多个 $opt_meta_author = get_post_meta($post->ID, 'opt_meta_author', true); <select name="opt_meta_author" id="opt_meta_author" multiple="multiple"> <?php $auth_args = array( 'post_type' => 'author'

我制作了元框,在这个框中,我用多个

$opt_meta_author = get_post_meta($post->ID, 'opt_meta_author', true);

<select name="opt_meta_author" id="opt_meta_author" multiple="multiple">
    <?php
        $auth_args = array(
            'post_type' => 'author',
            'orderby' => 'title',
            'order' => 'ASC'
        );

        $authors = new WP_Query($auth_args);

        while($authors->have_posts()) :
            $authors->the_post();
    ?>
        <option value="<?php echo the_title() ?>">
            <?php echo the_title() ?>
        </option>
    <?php
        endwhile;
    ?>
</select>

$\u POST['opt\u meta\u author'])
var转储是什么?如果它是一个数组,则使用
内爆
将其转换为字符串,并将字符串保存在数据库中

无任何变化,它只给出了这个-s:6:“Nadeem”@deemi.exe如果选择多个,则它将作为数组传递给服务器,并且在保存到数据库之前必须序列化。我执行此操作$opt_meta_author=serialize($\u POST['opt_meta_author']);更新帖子元($post->ID,$opt\u meta\u author',$opt\u meta\u author);当我用多个选择值保存时,它只给我一个值这是一个字符串,你能告诉我如何在dbI guess
update\u post\u meta($post->ID,'opt\u meta\u author',$opt\u meta\u author)中保存吗应该在数据库中进行保存。我使用过很多人的内爆和它的工作,但我犯的一个错误是,使用内爆()做这件事和它的工作都很好
$opt_meta_author = $_POST['opt_meta_author'];
update_post_meta( $post->ID, 'opt_meta_author', $opt_meta_author);
$opt_meta_author = unserialize(get_post_meta($post->ID, 'opt_meta_author', true));

<select name="opt_meta_author" id="opt_meta_author" multiple="multiple">
                <?php
                    $auth_args = array(
                        'post_type' => 'author',
                        'orderby' => 'title',
                        'order' => 'ASC'
                    );
                $authors = new WP_Query($auth_args);

                while($authors->have_posts()) :
                    $authors->the_post();
            ?>
                    <option value="<?php echo the_title() ?>">
                        <?php echo the_title() ?>
                    </option>
            <?php
                endwhile;
            ?>
            </select>
$opt_meta_author = serialize($_POST['opt_meta_author']);