0

Any idea, how I would get this to save? I have several select boxes that are done with the standard option statement. This one has me stumped on how to get it to save.

<p>
<?php
    $options = get_option( 'name' );

    $names = explode( PHP_EOL, $options );
    ?>


    <label for="title" class="timeshare-row-title"><?php _e( 'Property Name:', 'timeshare-textdomain' )?></label>
    <select name="Name">
    <?php foreach ( $names as $name ) {
        printf(
            '<option value="%s">%s</option>',
            $name,
            $name
        );
    } ?>

    </select>

Updated Section:

function timeshare_meta_save( $post_id ) {

// Checks save status
$is_autosave = wp_is_post_autosave( $post_id );
$is_revision = wp_is_post_revision( $post_id );
$is_valid_nonce = ( isset( $_POST[ 'timeshare_nonce' ] ) && wp_verify_nonce( $_POST[ 'timeshare_nonce' ], basename( __FILE__ ) ) ) ? 'true' : 'false';

// Exits script depending on save status
if ( $is_autosave || $is_revision || !$is_valid_nonce ) {
    return;
}

// Checks for input and sanitizes/saves if needed
// Checks for input and saves if needed
if( isset( $_POST[ 'name' ] ) ) {
update_post_meta( $post_id, 'name', $_POST[ 'name' ] );

}

  • 1
    Can you show up how you're saving your metadata? I'm assuming it's in the save_post hook – Howdy_McGee Nov 15 '15 at 3:32
  • @Howdy_McGee I added the extra code you requested. – John Lucey Nov 15 '15 at 3:43
  • I'm not entirely sure $_POST keeps case but try changing name to Name with a capital N. – Howdy_McGee Nov 15 '15 at 3:44
  • @Howdy_McGee not a winner, I think it has something to do with no selected() bieng included but I have not found were it would go. – John Lucey Nov 15 '15 at 4:08
  • I don't see where you're creating your nonce nor where you're getting your post meta. Looks like you're using get_option() instead of get_post_meta(). – Howdy_McGee Nov 15 '15 at 4:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.