Advanced Search Query for custom meta or taxonomies (3 posts)

  1. robmuzo
    Posted 4 years ago #

    Hi I am looking to implement a custom search on my site.

    It could be done based on custom taxonomies or custom meta via a custom post type.

    What I need to do is have a search function what filters by:

    2.dropdown option 1 (Based on Taxonomies or Custom Meta)
    3.dropdown option 2 (Based on Taxonomies or Custom Meta)

    Could anyone point me in what would be the best option to go with Taxonomies or Custom Meta and how I might go about creating this search?

    So far I have come up with this for meta:

    <form name="search" action="" method="get">
      <select name="option">
      $metakey = 'option';
      $options = $wpdb->get_col($wpdb->prepare("SELECT DISTINCT meta_value FROM $wpdb->postmeta WHERE meta_key = %s ORDER BY meta_value ASC", $metakey) );
      if ($options) {
        foreach ($options as $option) {
          echo "<option value=\"" . $option . "\">" . $option . "</option>";
      <input type="submit" value="search" />

    and this if using Taxonomies:

    <form role="search" method="get" id="searchform" action="<?php bloginfo('siteurl'); ?>">
        <label class="screen-reader-text" for="s">Search for:</label>
        <input type="text" value="" name="s" id="s" />
       <br/><?php wp_dropdown_categories( 'taxonomy=option1' ); ?>
        <?php wp_dropdown_categories( 'taxonomy=option2' ); ?>
        <input type="submit" id="searchsubmit" value="Search" />

    I think I would prefer to go down the meat root.

    Any ideas?


  2. robmuzo
    Posted 4 years ago #

    meta even

  3. robmuzo
    Posted 4 years ago #

Topic Closed

This topic has been closed to new replies.

About this Topic