WordPress.org

Support

Support » How-To and Troubleshooting » Advanced Search Query for custom meta or taxonomies

Advanced Search Query for custom meta or taxonomies

  • Rob JH
    Participant

    @robmuzo

    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:

    1.Keyword
    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">
      <?php
      $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>";
        }
      }
      ?>
      </select>
      <input type="submit" value="search" />
    </form>

    and this if using Taxonomies:

    <form role="search" method="get" id="searchform" action="<?php bloginfo('siteurl'); ?>">
      <div>
        <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" />
      </div>
    </form>

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

    Any ideas?

    Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Advanced Search Query for custom meta or taxonomies’ is closed to new replies.