Support » Themes and Templates » Saving metabox select arrays

  • Resolved obidos


    Hi All,

    I have a created a custom meta box which is a dropdown set to allow multiple selects. This works well but I have no idea how to save the array.

    Here is what generates the select box within the WordPress admin area:-

    function os_linkto_meta_box_html() {
    	global $post;
    	echo '<select name="os_linkto_product[]" id="os_linkto_product" multiple="yes" size="10">';
    	echo '<option value="">-</option>';
    	$val = get_post_meta($post->ID, 'os_linkto_product', true);
    	$q = get_posts('post_type=products&post_parent=0&numberposts=-1&orderby=menu_order&order=ASC');
    	foreach ($q as $obj)
    		echo '<option value="'.$obj->ID.'" "checked="checked">'.$obj->post_title.'</option>';
    	echo '</select>';

    I now need to save the selected option when the user clicks Update on the page.

    I then need to show the full list and keep the selected items highlighted. As the user may want to select more or remove some selections.

    What do I add inside here to save the array os_linkto_product[]

    Thank you kind people.

Viewing 1 replies (of 1 total)
  • I have worked out how to save the data in an array like so:-

    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
      return $post_id;
    } else {
      $boxes = implode(",", $_POST['os_linkto_product']);
      update_post_meta($post_id, "os_linkto_product", $boxes);

    No I need to be able to show the list with the selected items highlighted. Any ideas?

    I have the id’s of the product name saved as a meta key called os_linkto_product and the meta values 49,61,51.

    So I need the products relating to id 49,61,51 highlighted in the list.

    Any ideas?

    Thank you

Viewing 1 replies (of 1 total)
  • The topic ‘Saving metabox select arrays’ is closed to new replies.