WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] select list of categorys with the option multiple (4 posts)

  1. paka
    Member
    Posted 3 years ago #

    Hello,

    I want to display a select form with the posibility to select multiple categorys.
    With wp_dropdown_categories you can only select one.
    Is there any WP function, to do this, or have I to do it per querry to the table wp_terms. If this is so, how can I tell there categories from tags.

    LG
    Paka

    PS. I hope, it's possible, to understand my question, but I'm not acustomed to write in english.

  2. paka
    Member
    Posted 3 years ago #

    Second problem solved.

    I found the tables, to select the categories,:-) but this was'nt the reason, why I posted this question.
    You find the categories and tell them from tags, with the tables wp_terms and wp_term_taxonomy.

    It would be nice, if there is a solution to the first one, because I would prefer a WP function, and this is, why I asked.

    Hopefull
    Paka

  3. Mark / t31os
    Moderator
    Posted 3 years ago #

    You could hack the multiple selection on there using str_replace with wp_dropdown_categories, and could probably do something similar for wp_list_categories..

    $select_cats = wp_dropdown_categories( array( 'echo' => 0 ) );
    $select_cats = str_replace( 'id=', 'multiple="multiple" id=', $select_cats );
    echo $select_cats;
  4. paka
    Member
    Posted 3 years ago #

    Hello Mark / t31os
    tank you, this was quick.

    It works, the only thing, I had to change from your posted code was, that I had to change the name attribute too, to get an array $_POST['cat'] instead of only one value. It has to be name='cat[]'. But this is only a xhtml detail, the point was, to use str_replace on the return value of wp_dropdown_categories.
    The code I use now is this:

    $select_cats = wp_dropdown_categories( array( 'echo' => 0 ) );
    $select_cats = str_replace( "name='cat' id=", "name='cat[]' multiple='multiple' id=", $select_cats );

Topic Closed

This topic has been closed to new replies.

About this Topic