Support » Plugins » Hacks » Custom Post Type dropdown not saving values

  • Hi I’m using a custom post type and my values are saving to the database correctly, but the dropdown box is not holding those valued after the update from the user. Here is the function that contains the dropdown

    `// The Callback for Page Template Assignmets Metabox
    function pagetemplate() {
    global $post;
    // Noncename needed to verify where the data originated
    echo ‘<input type=”hidden” name=”pagetemplatemeta_noncename” id=”pagetemplatemeta_noncename” value=”‘ .
    wp_create_nonce( plugin_basename(__FILE__) ) . ‘” />’;
    // Get the title data if its already been entered

    $template = !empty($post->page_template) ? $post->page_template : false;

    ?>

    <label class=”screen-reader-text” for=”page_template”><?php _e(‘Page Template’) ?></label>
    <select name=”page_template” id=”page_template”>
    <option value=’default’><?php _e(‘Default Template’); ?></option>
    <?php template_dropdown($template); ?>
    </select>

    <?php

    }

    function template_dropdown( $default = ” ) {
    $templates = get_page_templates();
    ksort( $templates );
    foreach (array_keys( $templates ) as $template )
    : if ( $default == $templates[$template] )
    $selected = ” selected=’selected'”;
    else
    $selected = ”;
    echo “\n\t<option value='”.$templates[$template].”‘ $selected>$template</option>”;
    endforeach;
    }’

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Rob Myrick

    (@rm2773)

    Sorry I thought my code would post differently

    Moderator bcworkz

    (@bcworkz)

    You closed your code with an apostrophe instead of a backtick 😉

    You might try $default === $templates[$template] (equal value and type) I’ve had a similar issue with == working as expected in foreach loops. I’ve no explanation why, makes no sense.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom Post Type dropdown not saving values’ is closed to new replies.