WordPress.org

Ready to get started?Download WordPress

Forums

Dropdown search select and filter? (6 posts)

  1. Arash
    Member
    Posted 3 years ago #

    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

  2. Mark / t31os
    Moderator
    Posted 3 years ago #

    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).

  3. Arash
    Member
    Posted 3 years ago #

    Thank you mark. That does indeed work, but makes things less clear for the user. Choosing between 4x10 words is less of a problem than 1x40 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.

  4. Mark / t31os
    Moderator
    Posted 3 years ago #

    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..

  5. Arash
    Member
    Posted 3 years ago #

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

  6. Arash
    Member
    Posted 3 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic