1

I am working on an add-content front end form (posts in this case).

I am able to display, and add, categories and taxonomies to posts correctly with the following:

<div class="checkbox">
    <?php wp_terms_checklist( 0, array( 'taxonomy' => 'category', ) ); ?>
</div>    
<div class="checkbox">
    <?php wp_terms_checklist( 0, array( 'taxonomy' => 'city', ) ); ?>
</div>

Update #1, my first mistake was wrapping the <li>in a <div class="checkbox">. I have simply wrapped the WP terms function in a <ul class="list-inline">, but more can be done clearly. wp terms inline

Now the lists display as desired inline, but question is still valid. How do I modify the <li> of the Walker_Category_Checklist for more than one taxonomy?

So far I've got (functions.php):

require_once( ABSPATH . '/wp-admin/includes/template.php' );

class Stdy_Custom_Tree_List extends Walker_Category_Checklist
{
    public $tree_type = 'category';

    public $db_fields = array ( 'parent' => 'parent', 'id' => 'term_id' );

    public function start_lvl( &$output, $depth = 0, $args = array() ) {
        $output .= "<ul class='inline'>\n";
    }

    public function end_lvl( &$output, $depth = 0, $args = array() ) {
        $output .= "</ul>\n";
    }

    public function start_el( &$output, $category, $depth = 0, $args = array(), $current_object_id = 0 ) {
        $output .= "\n<li id='{$taxonomy}-{$category->term_id}'$class>" . 
            '<label class="selectit"><input value="' . $category->term_id . 
            '" type="checkbox" name="' . $name . '[]" id="in-' . $taxonomy . 
            '-' . $category->term_id . '"' . 
            checked( in_array( $category->term_id, $args['selected_cats'] ), true, false ) . 
            disabled( empty( $args['disabled'] ), false, false ) . ' /> ' . 
            esc_html( apply_filters( 'the_category', $category->name ) ) . '</label>';
    }

    public function end_el( &$output, $category, $depth = 0, $args = array() ) {
        $output .= "</li>\n";
    }
}

I think code is required to conditionally load the $output so that when walking the taxonomy displays the right HTML for:

Categories:

<input value="85" type="checkbox" name="post_category[]" id="in-category-85">

Taxonomy:

<input value="10" type="checkbox" name="tax_input[city][]" id="in-city-10">

I am a bit lost, thanks!

0

Your Answer

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

Browse other questions tagged or ask your own question.