Hi I made a theme options by this tutorial

This options have multicheck type by checkboxes. I don't know how to make it work. I'm try to exclude page using this multicheck. This is my array with options:

$pages = get_pages('sort_column=post_parent,menu_order');
$pageids = array();
    foreach ($pages as $page) {
        $pageids[$page->ID]= $page->post_title;
array( "name" => "Exclude page",
        "desc" => "",
        "id" => $shortname."_excludepage",
        "type" => "multicheck",
        "options" => $pageids,
        "std" => ""),

This screen show how this function looks in my DB:


512 is the ID of a page that I try to exclude.

Look's like this in admin:


In my template I've use this standart method for exclusion:


Please help me with this function! Thank you!


Want some honest advice? Work from a better code base..

Though, it's not your fault, there are hundreds of blogs with variations of similar code, i'm not sure where it originated, but i see similar code "alot"...

If you can get by without the hand holding and just manage with a good code base, i'd suggest the following..


It's not the most fancy or advanced example, but the approach is sound, it only uses a single option to store all the values and also uses the settings api for handling options.

  • +1, altough the themeshaper code could also be improved, but it's much better than OP's tutorial source Dec 19 '10 at 16:10
  • Yes, totally agree, but there's really not many good examples to be found, that's the best i've found that keeps the information short and sweet(to the point). I'd love to see a better example for themes, i couldn't find one (search terms are too general for this kind of information) from some brief searching.
    – t31os
    Dec 19 '10 at 16:28
  • Thank you for the link. Yes it's much better when uses a single option but to many work need to made for implement this options. clark-technet.com/2010/01/… -Maybe this much better? Dec 19 '10 at 16:50
  • Unfortunately that approach also uses several options(ie. not singular).. again looks like it's based of the same code as the previous site you linked to.
    – t31os
    Dec 19 '10 at 17:01
  • ok, first thing, using a array with fields like "textarea", "checkbox" etc.., then using foreach(type...) is ridiculous :) The theme options need to be flexible. You may want to add text, images above, or below a certain option... Try my example from the linked question and after you implement that for your site I can help you add a option that uses multiple checkboxes. And you'll see how easy and little code it uses... Dec 19 '10 at 17:02

Assuming your back-end works, and you can check multiple fields, and that the field values are really stored as an array, use:

$exclude = get_option('src_excludepage');
      "exclude" => implode(',', $exclude['options']),

PS: the tutorial you use has a pretty weird way of handling "multicheck". A much easier method is to append [] to the checkbox input names...


in the mytheme_admin() function add another case:

 case "page_multicheck":

  $pages = get_pages('sort_column=post_parent,menu_order');
  $pageids = array();
  foreach ($pages as $page){
    $pageids[$page->ID] = $page->post_title;

    $input_id = $value['id'] . '_' . $page->ID;
    $checkbox_setting = get_settings($value['id']);
    if (in_array($page->ID, $checkbox_setting)) $checked = "checked=\"checked\""; else $checked = "";
     <input type="checkbox" name="<?php echo $value['id']; ?>[]" id="<?php echo $input_id; ?>" <?php echo $checked; ?> />
     <label for="<?php echo $input_id; ?>"><?php echo $page->post_title; ?></label
     ><br />

in the $options array remove the old option and add:

  array("name" => "Exclude page",
        "desc" => "",
        "id" => $shortname."_excludepage",
        "type" => "page_multicheck",
        "options" => array(),
        "std" => ""),

now, theoretically my code above should work...

  • @AmbitiousAmoeba: If you have a good tutorial give me a link. Your solutions doesn't work. I have an error on pages: Warning: implode() [function.implode]: Invalid arguments passed in Z:\home\mysite.net\www\wp-content\themes\dddd\content.php on line 21 Dec 19 '10 at 14:45
  • add a line with print_r($exclude); before wp_list_pages and post here what you see Dec 19 '10 at 14:50
  • @AmbitiousAmoeba: Nothing is happen. All still on the same place. Dec 19 '10 at 15:20
  • well the problem is that you don't know the option name :) try replacing in my code 'src_excludepage' with 'src_excludepage_512' (the one from you db screenshot). also do a print_r so we can see if it's really a array... Dec 19 '10 at 15:29
  • @AmbitiousAmoeba: Now they show true, like in db for options name. I think instead true must be pageID and options name must be without numbers only src_excludepage. Dec 19 '10 at 15:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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