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 am slowly but surely chipping away at my first wordpress theme. I tried to make all of the aesthetics have different options, but well categorized so it is not overwhelming.

So in my theme customizer page I have different checkboxes that could distinguish different options for a certain components style. For instance I could have two checkboxes to distinguish what button type the user wants.

So my question is:

How can I automatically uncheck one checkbox if the another in it's group is checked? I figure this will prevent me from having different options for the same element on the page checked and potentially messing something up. I figure if statements are probably the only way to go but I am unsure how to add them since I didn't create the page, it is all done using the theme customizer API.

I am starting to think I should of used an options page instead, even though it is supposed to be a thing of the past and doesn't provide live previews, but it seems like it would add more flexibility.

share|improve this question
    
It is though, because it uses the theme customizer api. I don't actually write any of the code to create the forms so I don't control it. I add which control I want and link it to a setting. What I really need to know is how can I gain control of the form controls so I can write the logic? Also some groups may need to boxes checked off while the other ones are unchecked. I don't know if radio buttons will help me there. –  user1632018 Oct 9 '13 at 2:31
    
Have a look at this, wordpress.stackexchange.com/questions/4991/… , to toggle multiple checkbox states use jQuery. –  Wyck Oct 9 '13 at 6:27

1 Answer 1

up vote 1 down vote accepted

Your description makes it sound like you need a radio button. Radio buttons by design are exclusive-- only one button per button set can be checked at any one time.

The Settings API supports radio boxes, though the documentation for using them is sparse. I had to dig around a bit, and experiment. The key is the second parameter of add_control. You need to pass 'type' =>radio'and provide achoices` array for the radio button values.

function radio_controls_wpse_117203($wpc) {

  $wpc->add_setting(
    'radio_control_wpse_117203',
    array(
      'default' => 'hi',
    )
  );

  $wpc->add_section(
    'radio_section_wpse_117203',
    array(
      'title' => 'Radio WPSE 117203',
      'description' => 'A holder for our radio buttons.',
    )
  );

  $wpc->add_control(
    'radio_control_wpse_117203',
    array(
      'type' => 'radio',
      'label' => 'Salutation',
      'section' => 'radio_section_wpse_117203',
      'choices' => array(
        'hi' => 'Hi',
        'howdy' => 'Howdy',
      ),
    )
  );

}
add_action('customize_register','radio_controls_wpse_117203');
share|improve this answer
    
I modified the customizer to use the radio buttons instead and it really helps. Thank you, I appreciate it. –  user1632018 Oct 10 '13 at 16:57
    
It seems that the default value isn't working for me. I am not sure why. It works fine when I change the value in theme customizer and save it. It is only the default value. Do you know why this could be? –  user1632018 Nov 16 '13 at 5:58

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.