0

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

2
  • 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
    Commented May 28, 2012 at 9:04
  • You mean: return $catsArray; or echo $catsArray; ? If so none of those work..What else could I try? Thanks'
    – Alvaro
    Commented Jun 4, 2012 at 12:14

1 Answer 1

2

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!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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