WordPress.org

Ready to get started?Download WordPress

Forums

Saving Dropdowns & Checkboxes in CPT Meta Box (1 post)

  1. designinglightning
    Member
    Posted 1 year ago #

    I've been struggling with this for over a week now, and I can't seem to find the right resources. I'm trying to save information in a custom meta box for a profile of different camps. All of my input text and textboxes are saving, but dropdowns and checkboxes don't save at all. Here is part of the code

    function admin_init(){
    	add_meta_box("campingentry_meta", "Camp Details", "camping_meta", "camping", "normal", "high");
    }
    
    function camping_meta() {
      global $post;
      $custom = get_post_custom($post->ID);
      $state = $custom["camping_state"][0];
      $sessionlength = $custom["camping_sessionlength"][0];
     ?>
    
    	<div id='camping_form_container'>
    			<p><label>State/Province</label><br />
    			<select name="state_dropdown" id="state_dropdown">
    				<option value="AL" <?php selected( $state, 'AL' ); ?>>Alabama</option>
    				<option value="AK" <?php selected( $state, 'AK' ); ?>>Alaska</option>
    				<option value="AZ" <?php selected( $state, 'AZ' ); ?>>Arizona</option>
    				<option value="AR" <?php selected( $state, 'AR' ); ?>>Arkansas</option>
    				<option value="CA" <?php selected( $state, 'CA' ); ?>>California</option>
    				<option value="CO" <?php selected( $state, 'CO' ); ?>>Colorado</option>
    				<option value="CT" <?php selected( $state, 'CT' ); ?>>Connecticut</option>
    				<option value="DE" <?php selected( $state, 'DE' ); ?>>Delaware</option>
    				<option value="DC" <?php selected( $state, 'DC' ); ?>>District Of Columbia</option>
    				<option value="FL" <?php selected( $state, 'FL' ); ?>>Florida</option>
    				<option value="GA" <?php selected( $state, 'GA' ); ?>>Georgia</option>
    				<option value="HI" <?php selected( $state, 'HI' ); ?>>Hawaii</option>
    				<option value="ID" <?php selected( $state, 'ID' ); ?>>Idaho</option>
    				<option value="IL" <?php selected( $state, 'IL' ); ?>>Illinois</option>
    				<option value="IN" <?php selected( $state, 'IN' ); ?>>Indiana</option>
    				<option value="IA" <?php selected( $state, 'IA' ); ?>>Iowa</option>
    				<option value="KS" <?php selected( $state, 'KS' ); ?>>Kansas</option>
    				<option value="KY" <?php selected( $state, 'KY' ); ?>>Kentucky</option>
    				<option value="LA" <?php selected( $state, 'LA' ); ?>>Louisiana</option>
    				<option value="ME" <?php selected( $state, 'ME' ); ?>>Maine</option>
    				<option value="MD" <?php selected( $state, 'MD' ); ?>>Maryland</option>
    				<option value="MA" <?php selected( $state, 'MA' ); ?>>Massachusetts</option>
    				<option value="MI" <?php selected( $state, 'MI' ); ?>>Michigan</option>
    				<option value="MN" <?php selected( $state, 'MN' ); ?>>Minnesota</option>
    				<option value="MS" <?php selected( $state, 'MS' ); ?>>Mississippi</option>
    				<option value="MO" <?php selected( $state, 'MO' ); ?>>Missouri</option>
    				<option value="MT" <?php selected( $state, 'MT' ); ?>>Montana</option>
    				<option value="NE" <?php selected( $state, 'NE' ); ?>>Nebraska</option>
    				<option value="NV" <?php selected( $state, 'NV' ); ?>>Nevada</option>
    				<option value="NH" <?php selected( $state, 'NH' ); ?>>New Hampshire</option>
    				<option value="NJ" <?php selected( $state, 'NJ' ); ?>>New Jersey</option>
    				<option value="NM" <?php selected( $state, 'NM' ); ?>>New Mexico</option>
    				<option value="NY" <?php selected( $state, 'NY' ); ?>>New York</option>
    				<option value="NC" <?php selected( $state, 'NC' ); ?>>North Carolina</option>
    				<option value="ND" <?php selected( $state, 'ND' ); ?>>North Dakota</option>
    				<option value="OH" <?php selected( $state, 'OH' ); ?>>Ohio</option>
    				<option value="OK" <?php selected( $state, 'OK' ); ?>>Oklahoma</option>
    				<option value="OR" <?php selected( $state, 'OR' ); ?>>Oregon</option>
    				<option value="PA" <?php selected( $state, 'PA' ); ?>>Pennsylvania</option>
    				<option value="RI" <?php selected( $state, 'RI' ); ?>>Rhode Island</option>
    				<option value="SC" <?php selected( $state, 'SC' ); ?>>South Carolina</option>
    				<option value="SD" <?php selected( $state, 'SD' ); ?>>South Dakota</option>
    				<option value="TN" <?php selected( $state, 'TN' ); ?>>Tennessee</option>
    				<option value="TX" <?php selected( $state, 'TX' ); ?>>Texas</option>
    				<option value="UT" <?php selected( $state, 'UT' ); ?>>Utah</option>
    				<option value="VT" <?php selected( $state, 'VT' ); ?>>Vermont</option>
    				<option value="VA" <?php selected( $state, 'VA' ); ?>>Virginia</option>
    				<option value="WA" <?php selected( $state, 'WA' ); ?>>Washington</option>
    				<option value="WV" <?php selected( $state, 'WV' ); ?>>West Virginia</option>
    				<option value="WI" <?php selected( $state, 'WI' ); ?>>Wisconsin</option>
    				<option value="WY" <?php selected( $state, 'WY' ); ?>>Wyoming</option>
                </select>
    
                <p><strong>Session Length</strong><br />
    			<label>One Week</label> <input type="checkbox" nname="camping_sessionlength" id="oneweek" value="oneweek" <?php checked( $checked, $current, $echo ); ?>>
    <label>Two Weeks</label><input type="checkbox" name="camping_sessionlength"  id="twoweeks" value="twoweeks" <?php checked( $checked, $current, $echo ); ?>><br />
    			<label>Three Weeks</label> <input type="checkbox" name="camping_sessionlength"  id="threeweeks" value="threeweeks" <?php checked( $checked, $current, $echo ); ?>>
    <label>Four Weeks</label> <input type="checkbox" name="camping_sessionlength"  id="fourweeks" value="fourweeks" <?php checked( $checked, $current, $echo ); ?>><br />
    			<label>Five Weeks</label> <input type="checkbox" name="camping_sessionlength"  id="fiveweeks" value="fiveweeks" <?php checked( $checked, $current, $echo ); ?>>
    <label>Six Weeks</label> <input type="checkbox" name="camping_sessionlength" id="sixweeks" value="sixweeks" <?php checked( $checked, $current, $echo ); ?>><br />
    			<label>Seven Weeks</label> <input type="checkbox" name="camping_sessionlength"  id="sevenweeks" value="sevenweeks" <?php checked( $checked, $current, $echo ); ?>>
    <label>Eight Weeks</label> <input type="checkbox" name="camping_sessionlength"  id="eightweeks" value="eightweeks" <?php checked( $checked, $current, $echo ); ?>></p>
           </div>
    
     <?php
    }
    
    add_action('save_post', 'save_details');
    
    function save_details(){
      global $post;
      update_post_meta($post->ID, "camping_state", $_POST["camping_state"]);
      update_post_meta($post->ID, "camping_sessionlength", $_POST["camping_sessionlength"]);
    }

    I assume it has to do with creating an array to save individual pieces (at least for the checkboxes), but I'm not totally sure where I should be doing that.

    Your help is MUCH appreciated!

Topic Closed

This topic has been closed to new replies.

About this Topic

  • RSS feed for this topic
  • Started 1 year ago by designinglightning
  • This topic is not resolved
  • WordPress version: 3.6