Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a basic Admin panel allowing Admin to save options using Checkbox. Checkboxes are used as multiple selection is necessary for the option

So, Admin Option - Checkbox 1 - Checkbox 2 - Checkbox 3 etc

My Checkboxes are generated on the fly, successfully with

<input type="checkbox" name="firm" id="firm-<?php echo esc_attr( $term->slug ); ?>" value="<?php echo esc_attr( $term->slug ); ?>" <?php checked( true, is_object_in_term( $user->ID, 'firm', $term ) ); ?> /><input type="checkbox" name="firm" id="firm-<?php echo esc_attr( $term->slug ); ?>" value="<?php echo esc_attr( $term->slug ); ?>" <?php checked( true, is_object_in_term( $user->ID, 'firm', $term ) ); ?> />

Then when saving my option, I am trying to do it with

wp_set_object_terms( $user_id, array( $term ), 'firm', false);

BUt only the last term is saved and not the array (if more than 1 checked)

Any idea?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Change the name of the checkboxes fromfirm to firm[].

Then, when you go to save the checkboxes

$terms = $_POST['firm'];

will give you an array of term slugs that can be checked/sanitized prior to using wp_set_object_terms to add the terms...

wp_set_object_terms( $user_id, $terms, 'firm', false);
share|improve this answer
    
Hi Stephen, Thanks for your answer. You put me in the right direction, I was checking $_post['firm'] with $term = esc_attr( $_POST['firm'] ) which was causing problem. Thanks again –  salocin Feb 6 '12 at 9:34
    
@Salocin - no problem! Could you except answers that solve your questions - it helps others know it's been solved, and what the solution was :D. –  Stephen Harris Feb 6 '12 at 9:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.