WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

My website allows uses to post posts of a custom post type ("place").

I would like to display the same "Categories" meta box seen in WordPress dashboard when you add or edit a post on frontend:
backend categories meta box

This is because the "Categories" meta box or hierarichical checkboxes is simply the best way to view and edit the categories a post belongs to.

How do I the "Categories" meta box on frontend?

I do know JQuery so feel free to throw in JQuery stuffs if any. I would strongly prefer an approach to replicate what WordPress does for adding/ editing a post in backend, instead of a hack from scratch.

share|improve this question
up vote 3 down vote accepted

Try wp_terms_checklist() / wp_category_checklist. It will output a list of checkboxes named post_category.

You might need to include the source file too, because it's defined within administration files.

Or use a custom walker:

class MyCategoryWalker extends Walker_Category{

  public function start_el(&$output, $term, $depth, $args){

    $args = wp_parse_args(array(
      'name'    => 'my_category_input',
      'checked' => array(),

    ), $args);


    $checked = checked(in_array($term->term_id, $checked));

    ob_start(); ?>   

      <input type="checkbox" <?php $checked; ?> id="category-<?php print $term->term_id; ?>" name="<?php print $name; ?>[]" value="<?php print $term->term_id; ?>" />
      <label for="category-<?php print $term->term_id; ?>">
        <?php print esc_attr($term->name); ?>

    <?php // closing LI is added inside end_el

    $output .= ob_get_clean();

Use it like:

  'walker'   => new MyCategoryWalker(),
  'name'     => 'my_category_input',       // name of the input
  'selected' => array(2, 5, 10),           // checked items (category IDs)
share|improve this answer
wp_category_checklist works like a charm for me :) thanks – eric Oct 2 '12 at 1:00

Your Answer


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.