WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. robmuzo
    Member
    Posted 3 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:

    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.

  2. robmuzo
    Member
    Posted 3 years ago #

    meta even

  3. robmuzo
    Member
    Posted 3 years ago #

Topic Closed

This topic has been closed to new replies.

About this Topic