Multiple Select value saving Issue

i make meta box and in this i make select option with multiple

$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>

when i select multiple options it save only one option, i want to save selected options

Read More

is there any suggestions

Saving meta values

$opt_meta_author = $_POST['opt_meta_author'];
update_post_meta( $post->ID, 'opt_meta_author', $opt_meta_author);

Related posts

Leave a Reply

2 comments

  1. $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>
    

    To get multiple selected value while storing do this:

    $opt_meta_author = serialize($_POST['opt_meta_author']);