• pk-71

    (@pauljohnknight)


    Hi,

    I have a jobs custom post type that is currently using the wp_dropdown_categories() function within a WP search form so people will be able to filter jobs by salary level and job type.

    I would like to use input element checkboxes instead, so the user can select multiple taxonomy terms.

    From what I gather this is best done with wp_terms_checklist(), however I cannot seem to get it work. The information in the developer docs seems sparse to say the least.

    If I have a search form and wish to add two taxonomy terms lists for people to select items from how would I go about doing this?

    Basically the form has a keyword search box then two taxonomy lists to choose from, where users either search by a combination of keywords and taxonomies or just keywords etc

    Below is some pseudo code showing what I would like to achieve.

    <form method="get" action="<?php echo esc_url(site_url('/')); ?>">
        <label id="searchlabel" for="s">Search</label>
        <input id="s" name="s" type="search">
        <input type="hidden" name="post_type" value="jobs" />
    
        // add 1st instance of wp_terms_checklist() // job type taxonomy
    
        // add 2nd instance of wp_terms_checklist() // salary level taxonomy
            
        <input class="td search-jobs-button" type="submit" value="Search Jobs">
    </form>
Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    Agreed, sparse docs. One thing that’s not clear is that this is a back end function, it’s not available for front end use. I recommend getting an array of WP_Term objects with get_terms() and using that data to generate your own checklist. This can get tricky if you want a hierarchical list with children indented, but for a flat list it’s not too complicated to do.

Viewing 1 replies (of 1 total)
  • The topic ‘Add wp_terms_checklist() to a search form to search by taxonomy’ is closed to new replies.