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 building a theme and for the Theme Settings Page I followed this tutorial: http://wp.tutsplus.com/tutorials/using-the-settings-api-part-1-create-a-theme-options-page/

What I want now is to have a multi-checkbox with every category. This is what I should have:

$options[] = array(
    "section" => "zzz",  
    "id"      => HS_SHORTNAME . "_multicheckbox_inputs",  
    "title"   => __( 'Multi-Checkbox', 'hs_textdomain' ),  
    "desc"    => __( 'Some Description', 'hs_textdomain' ),  
    "type"    => "multi-checkbox",  
    "std"     => '',  
    "choices" => array( __('Category 1','hs_textdomain') . "|category1", __('Category 2','hs_textdomain') . "|category2", __('Category 3','hs_textdomain') . "|category3")
);

However I've tried multiple options but none of them gives me exactly as shown above. I think the answer is close to get_categories() function with no luck. Also tried:

function my_list_cats() {
    $cats = get_categories();
    foreach($cats as $cat) {
        $catsArray[] = __('' . $cat->cat_name . '','hs_textdomain') . "|" . $cat->category_nicename . "";
    }
    echo implode(', ', $catsArray);
}

And then:

"choices" => array(my_list_cats())

But no luck. Does anyone know a solution? Thank you very much

share|improve this question
    
seems to be a php problem more than WordPress related; try no to implode the results in your function; try to return the result instead echo –  Michael May 28 '12 at 9:04
    
You mean: return $catsArray; or echo $catsArray; ? If so none of those work..What else could I try? Thanks' –  Alvaro Jun 4 '12 at 12:14

1 Answer 1

up vote 2 down vote accepted

Thanks Michael for the tip. I finally got it. The solution is as follows:

$options[] = array(
    "section" => "zzz",  
    "id"      => HS_SHORTNAME . "_multicheckbox_inputs",  
    "title"   => __( 'Multi-Checkbox', 'hs_textdomain' ),  
    "desc"    => __( 'Some Description', 'hs_textdomain' ),  
    "type"    => "multi-checkbox",  
    "std"     => '',  
    "choices" => my_list_cats()
);

And in functions.php:

function my_list_cats() {
  $cats = get_categories();
  foreach($cats as $cat) {
      $catsArray[] = __('' . $cat->cat_name . '','hs_textdomain') . "|" . $cat->category_nicename . "";
  }
  return $catsArray;
}

Thanks again!

share|improve this answer

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.