• I have a search on my page that contains 3 elements…

    1) the text input
    2) a dropdown box of categories
    3) a dropdown box of tags

    I need someone to be able to type something in the field, select a category, and select a tag then press “search” and see only the results that fit those items.

    The input field works fine.
    The input field with the categories dropdown works fine.
    If I remove the categories dropdown, the input field with the tags dropdown works fine.

    What doesn’t work is all three together… basically the 2 dropdown boxes are conflicting, or WP doesn’t know what to do with them.

    So, my question is, how can I use 2 dropdown boxes in a search query?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter noelgreen

    (@noelgreen)

    Here’s a link to a site that shows exactly what I’m wanting to do. Does anyone know how to convert these tips into WordPress functionality?

    The Site With Example

    Thread Starter noelgreen

    (@noelgreen)

    Maybe using the “Tags” isn’t the best way to do this…

    Is there anyway to keep categories separate? Even make 2 sections in the “Write Post” area… 2 “Category” boxes.

    In one categories box you could have “cars,” “gifts,” and “decorations”, and then in the other categories box “Dallas,” “New York,” and “Seattle” as 3 other separate categories.

    So, someone writing a post could choose a category from both boxes, or multiple categories from each.

    THEN… make that so that there could be a dropdown for each set of categories… allowing readers of the blog to type in “Toys” in the input box… select “gifts” from the first dropdown, then “New York” from the 2nd dropdown and get results that only matched Toys in the Gifts / New York categories.

    Isn’t this possible??

    Thread Starter noelgreen

    (@noelgreen)

    Apparently this needs to be a plugin.

    I recently worked on a very similar task with multiple drop-downs that contained tags.

    First one simplified approach.
    Add posts from selected categories to ONE drop-down with some style-filtering:

    <form action="<?php $PHP_SELF ?>" name="searchbyname" id="searchbyname" >
    <select name="nameselect">
    <?php query_posts("cat=3,4&showposts=-1&orderby=title&order=asc"); ?>
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    
    <option <?php if(in_category(4)) echo 'style="font-weight: bold;"'; ?> value="<?php echo get_permalink(); ?>">
    <?php the_title_attribute('before=&after=');?>
    </option>
    
    <?php endwhile; ?><?php else : ?><?php //smething ?><?php endif; ?>
      </select>
      <input type="button" name="Button1" value="Go" />
    </form>

    —–
    With some java-script you could directly redirect on select.

    Second, a form with multiple drop-downs that hold manually defined tags to output only posts that contain the chosen tag combination.

    <form action="<?php $PHP_SELF ?>" method="post" name="searchbytags">
    
    <select name="group1">
    <option value="tag1">tag1</option>
    <option value="notype">No Choice</option>
    </select>
    
    <select name="group2">
    <option value="tag5">tag5</option>
    <option value="notype">No Choice</option>
    </select>
    <input type="hidden" name="sent" value="1">
    <input type="submit" name="Submit" value="search" />
    </form>

    —-
    Some hints to capture the data submitted by 2nd. example:

    <?php 
    
    $formfields = array("group1", "group2");
    $formdata=$GLOBALS["_REQUEST"];
    
    foreach ($formfields as $formfields2)
    {
    if ($formdata[$formfields2] !== "notype")
    $tagsearchall = $tagsearchall . $formdata[$formfields2] . "+";
    }
    
    $tagsearchall = "tag=" . substr($tagsearchall, 0, -1); //remove last " + "
    if ($tagsearchall !== "tag=+++") {echo "SEARCH TAG: $tagsearchall";}
    ?>

    —–
    Now pass $tagsearchall to the loop:

    <?php if ($_REQUEST["sent"]){?>
    <?php query_posts("$tagsearchall"); ?>
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    
    ... continue as usual and do a lot of fancy stuff here.

    Hope it helps.

    Thread Starter noelgreen

    (@noelgreen)

    Thanks!

    I have decided to, at this time, go a different direction on all this… but I’m saving this thread because your tips are excellent!!!

    Thanks again!

    Noelgreen,

    Thanks for commenting on my post

    My only other idea was to actually add columns in the WP_POST and give them identifiers from which I could search from.

    Then, put input boxes in my “Write Post” <form> section of the admin.(Post.php and post-new.php) So when I write a post, I can just select and enter the extra fields. BUT, I’m having problems getting the fields I added to actually write to the DB.

    Trust me if you know anything on making something like that work we can just forget about trying to do a complex search on info that is just scrambled in 2 columns.

    This a method I’ve tried before, and am going back to. I think I’ll have much more luck once I can figure it out.

    Hey Noel

    I’ve labored on this for a while now and I’ve finally managed to get a working WP version of what you’re looking for.

    I’ve explained the steps on creating a dynamic select menu on my WPGuru site..

    Hope it helps ??

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Searching with 2 Dropdown Boxes’ is closed to new replies.