Advertisement
damienoneill2001

WordPress Search Filter

May 26th, 2014
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.91 KB | None | 0 0
  1. <?php
  2. function adopt_custom_taxonomy_dropdown( $taxonomy, $orderby = 'date', $order = 'DESC', $limit = '-1', $name, $show_option_all = null, $show_option_none = null ) {
  3.     $args = array(
  4.         'orderby' => $orderby,
  5.         'order' => $order,
  6.         'number' => $limit,
  7.        
  8.     );
  9.     $terms = get_terms( $taxonomy, $args );
  10.     $name = ( $name ) ? $name : $taxonomy;
  11.     if ( $terms ) {
  12.         printf( '<select name="%s" class="postform">', esc_attr( $name ) );
  13.         if ( $show_option_all ) {
  14.             printf( '<option value="0">%s</option>', esc_html( $show_option_all ) );
  15.         }
  16.         if ( $show_option_none ) {
  17.             printf( '<option value="-1">%s</option>', esc_html( $show_option_none ) );
  18.         }
  19.         foreach ( $terms as $term ) {
  20.             printf( '<option value="%s">%s</option>', esc_attr( $term->slug ), esc_html( $term->name ) );
  21.         }
  22.         print( '</select>' );
  23.     }
  24.     }
  25.  
  26. //The following is then used to pull the results onto a results template:
  27. ?>
  28. <?php
  29.         if (isset($_GET["farm-type"]) && empty($_GET["location-farms"])){
  30.  
  31.         $farm_type = $_GET["farm-type"];
  32.  
  33.         $myquery1['tax_query'] = array(
  34.             array(
  35.                 'taxonomy' => 'farm-type',
  36.                 'terms' => array($farm_type),
  37.                 'field' => 'slug',
  38.  
  39.             ),
  40.         );
  41.         query_posts($myquery1);
  42.  
  43.         }
  44.         ?>
  45.  
  46.         <?php
  47.         if (isset($_GET["farm-type"]) && isset($_GET["location-farms"])){
  48.  
  49.         $farm_type = $_GET["farm-type"];
  50.         $farm_location = $_GET["location-farms"];
  51.  
  52.         $myquery2['tax_query'] = array(
  53.             array(
  54.                 'taxonomy' => 'farm-type',
  55.                 'terms' => array($farm_type),
  56.                 'field' => 'slug',
  57.             ),
  58.             array(
  59.                 'taxonomy' => 'location-farms',
  60.                 'terms' => array($farm_location),
  61.                 'field' => 'slug',
  62.             ),
  63.         );
  64.         query_posts($myquery2);
  65.  
  66.         }
  67.         ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement