WordPress.org

Support

Support » Plugins and Hacks » Hacks » Dropdown search select and filter?

Dropdown search select and filter?

  • WordPress search has the option to search multimple words

    /?s=searchtring1+searchstring2

    Is it possible to have 2 list of preselected searchkeywords as a dropdown and have wordpress press search those?

    I have tried

    <form role="search" method="get" id="searchform" action="<?php bloginfo('siteurl'); ?>">
      <div>
        <label class="screen-reader-text" for="s">Search for:</label>
    Type
    <select name='s' id='type' class='postform' >
      <option value='' selected='selected'>All</option>
      <option class="level-0" value="dog">Dog</option>
      <option class="level-0" value="cat">Cat</option>
    </select>	
    
    Color
    <select name='s' id='color' class='postform' >
      <option value='' selected='selected'>All</option>
      <option class="level-0" value="red">red</option>
      <option class="level-0" value="white">white</option>
      <option class="level-0" value="green">green</option>
    </select>	
    
       <input type="submit" id="searchsubmit" value="Search" />
      </div>
    </form>

    But the output is

    /?s=row1&s=row2

    rather than

    /?s=row1+row2

Viewing 5 replies - 1 through 5 (of 5 total)
  • The only way i can think of doing it would be to use a multiple selection dropdown(singular), that allows selection of multiple values, though i’m not sure how that will work out..

    <select multiple="multiple" name='s' id='type' class='postform' >

    You should then(hopefully) be able to select multiple values inside the dropdown..

    You won’t be able to use dual dropdowns with a form that uses the get method (just so that’s clear).

    Thank you mark. That does indeed work, but makes things less clear for the user. Choosing between 4×10 words is less of a problem than 1×40 words. Specially when filtering based on related words.

    So
    – Choose country
    – Choose state
    – Choose city

    Show all posts with mention of your city.

    I am going to try giving the second drop a differnt name so that we get

    /?s=row1&second=row2

    and then do a modrewrite for &second= to +

    On another site someone suggested

    There may be a way to do this with javascript.

    Add a hidden textbox with the name “s” and rename the selectboxes.

    On each select onchange attribute call a javascript that adds the current selectbox’s value to the hidden textbox.

    When the form is submitted the hidden box have the value “dog red” and should be passed as ?s=dog+red

    I have no javascript knowledge and am trying to find examples for that.

    That’s a very good suggestion, but unfortunately JS is not one my strengths.. but it would work around the issue..

    Bear in mind, if you use the search in that way, users without JS will have no way to search, because the search will be dependant on that JS component working.. (the s field will be hidden with no value, making a search impossible for the non-JS user).

    Using a secondary query var as you suggested would be the preferable method in my opinion because it won’t have the same limitations the Javascript approach would..

    I have no JS knowledge so I am going to try some modrewrite using a second parameter.

    I cannot get redirects and string replaces to work. So that

    /?s=row1&sa=row2

    becomes

    /?s=row1+row2

    so I am going to test JS.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Dropdown search select and filter?’ is closed to new replies.