1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

new taxonomy in search

Discussion in 'PHP' started by lew1s666, Oct 13, 2014.

  1. #1
    Hi using wordpress properties search plugin. I have two categories (taxonomies). In the search box is set up just one. How can I add another one ? here is my search php code. I need to just create new taxonomy "features". Taxnomy "listing_type" is already there.


    
    <?php 
    function ar_taxonomy_dropdown( $taxonomy ) {
                    $terms = get_terms( $taxonomy );
                    if ( $terms ) {
                        $return = '<div class="searchItem"><span class="white-shadow">Property Type:</span> <select name="meta_tax" class="input-box">'.$taxonomy;
                            $return .= '<option value=""> Any </option>';
                        foreach($terms as $term) {
                            $return .= '<option value="'.$term->slug.'">'.$term->name.'</option>';
                        }
                        $return .= '</select></div>';
                        }
                        return $return;
                    } 
    
    
    
    
    
    function ar_search($return = false) { 
    include ('style-search-box.php');
    $output = '
    <div class="ar-search-span"> SEARCH </div>
    <div class="ar-search-box">
            <form method="get" id="searchform" action="'. esc_url( home_url() ).'">
           
                <div class="searchItem">
               
               
                   
                       
               
                </div>';
                 
                    $output .= ar_taxonomy_dropdown('listing_type');
                   
                   
              $output .= '
    
    
    
             
               
             
             
               
                <input type="hidden" name="post_type" value="listing" />                        
                <input type="submit" class="white-shadow" name="submit" id="ar-submit" value="Search" />
             
             
        </form>
        </div>';
        if ($return === true) {
            return $output;
        } else {
            echo $output;
        }
    }
    
    
    PHP:

    SEMrush
     
    lew1s666, Oct 13, 2014 IP
    SEMrush
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #2
    I think this should work:
    change the ar_taxonomy_dropdown-function to this:
    
    function ar_taxonomy_dropdown( $taxonomy,$taxonomy2 = false ) {
                    $terms = get_terms( $taxonomy );
                    $terms2 = ($taxonomy2 != false) ? get_terms( $taxonomy2 ) : '';
                    $return = '';            
      if ( $terms ) {
                        $return .= '<div class="searchItem">
                                               <span class="white-shadow">Property Type:</span>
                                               <select name="meta_tax" class="input-box">'.$taxonomy;
                         $return .= '<option value=""> Any </option>';
                                 foreach($terms as $term) {
                                      $return .= '<option value="'.$term->slug.'">'.$term->name.'</option>';
                                  }
                                       $return .= '</select>
                                                   </div>';
                        }
      if ( $terms2 ) {
                        $return .= '<div class="searchItem">
                                               <span class="white-shadow">Property Type:</span>
                                               <select name="meta_tax" class="input-box">'.$taxonomy2;
                         $return .= '<option value=""> Any </option>';
                                 foreach($terms2 as $term) {
                                      $return .= '<option value="'.$term->slug.'">'.$term->name.'</option>';
                                  }
                                       $return .= '</select>
                                                   </div>';
                        }
                
                        return $return;
                    }
    
    PHP:
    And change the calling line to this:
    
    $output .= ar_taxonomy_dropdown('listing_type','features');
    
    PHP:
    Not tested, no idea if it'll work
     
    PoPSiCLe, Oct 13, 2014 IP
  3. lew1s666

    lew1s666 Member

    Messages:
    101
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    30
    #3
    thanks! working!
     
    lew1s666, Oct 13, 2014 IP
  4. lew1s666

    lew1s666 Member

    Messages:
    101
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    30
    #4
    its working fine but when i press Search button it wont show any results. I tried to ask developers of the plugin but they wont support me coz I customized the plugin. doyou know why no results ?
    http://bdmproperty.ie/properties/

    mike
     
    lew1s666, Oct 14, 2014 IP
  5. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #5
    I'm sorry, that I do not know - depending on how the search is done, it might try to match on the wrong criteria - for instance AND instead of OR, or maybe trying to match several criteria, or using one criteria wrongly. The problem is most likely in the query, not in the forms themselves
     
    PoPSiCLe, Oct 14, 2014 IP
  6. lew1s666

    lew1s666 Member

    Messages:
    101
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    30
    #6
    so how i can get to work. here is the main code.

    
    <?php 
    function ar_taxonomy_dropdown( $taxonomy,$taxonomy2 = false ) {
                    $terms = get_terms( $taxonomy );
                    $terms2 = ($taxonomy2 != false) ? get_terms( $taxonomy2 ) : '';
                    $return = '';            
      if ( $terms ) {
                        $return .= '<div class="searchItem">
                                              <span class="white-shadow">Property Type:</span>
                                              <select name="meta_tax" class="input-box">'.$taxonomy;
                         $return .= '<option value=""> Any </option>';
                                 foreach($terms as $term) {
                                      $return .= '<option value="'.$term->slug.'">'.$term->name.'</option>';
                                  }
                                       $return .= '</select>
                                                  </div>';
                        }
      if ( $terms2 ) {
                        $return .= '<div class="searchItem">
                                              <span class="white-shadow">Location:</span>
                                              <select name="meta_tax" class="input-box">'.$taxonomy2;
                         $return .= '<option value=""> Any </option>';
                                 foreach($terms2 as $term) {
                                      $return .= '<option value="'.$term->slug.'">'.$term->name.'</option>';
                                  }
                                       $return .= '</select>
                                                  </div>';
                        }
               
                        return $return;
                    }
    
    
    
    
    
    function ar_search($return = false) { 
    include ('style-search-box.php');
    $output = '
    <div class="ar-search-span"> SEARCH </div>
    <div class="ar-search-box">
            <form method="get" id="searchform" action="'. esc_url( home_url() ).'">
           
                <div class="searchItem">
               
               
                   
                       
               
                </div>';
                 
                    $output .= ar_taxonomy_dropdown('listing_type','location');
                   
                   
              $output .= '
    
    
    
             
               
             
             
               
                <input type="hidden" name="post_type" value="listing" />                        
                <input type="submit" class="white-shadow" name="submit" id="ar-submit" value="Search" />
             
             
        </form>
        </div>';
        if ($return === true) {
            return $output;
        } else {
            echo $output;
        }
    }
    [php]
    
    
    
    [php]
    <?php
    function ar_search_results(){
    get_header();
        include ('style.php');
       
        echo '<div class="ar-listing-wrap">
       
        <h1 class="page-title">Search Results:</h1>';
       
        include ('metaURL.php');
       
        function meta_query () {
           
        }
                        echo '<div class="ar-listing-wrap">';
                        $nodeHeight= get_option('nt_listHeight');
                        $nodeWidth= get_option('nt_listWidth');
                        global $wp_query;
                        $postPage = get_option('nt_perpageListing');
                        global $wp_query;
                        $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
                        echo '<div class="boatGallery">';
                        query_posts( array (
                            'posts_per_page' => $postPage, 
                            'paged'=>$paged,
                            'post_type' => 'listing',
                            'meta_query' => array(
                                array(
                                    'key' => '_general_nt_logo',
                                    'value' => array($priceMin, $priceMax),
                                    'type' => 'numeric',
                                    'compare' => 'BETWEEN'
                                ),
                                array(
                                    'key' => '_general_bedroom',
                                    'value' => array($bedMin, $bedMax),
                                    'type' => 'numeric',
                                    'compare' => 'BETWEEN'
                                ),
                                array(
                                    'key' => '_general_bathroom',
                                    'value' => array($bathMin, $bathMax),
                                    'type' => 'numeric',
                                    'compare' => 'BETWEEN'
                            )),
                            $poolMeta => array(
                                array(
                                    'key' => $poolTerm,
                                    'value' => $poolValue,  
                            )),
                            $garageMeta => array(
                                array(
                                    'key' => $garageTerm,
                                    'value' => $garageValue,  
                            )),
                            $fireplaceMeta => array(
                                array(
                                    'key' => $fireplaceTerm,
                                    'value' => $fireplaceValue,  
                            )),
                            $houseMeta => array(
                                array(
                                    'key' => $houseTerm,
                                    'value' => $houseValue,  
                            )),
                            $airMeta => array(
                                array(
                                    'key' => $airTerm,
                                    'value' => $airValue,  
                            )),
                           
                           
                           
                            $queryTax1 => array(
                                array(
                                    $tax => 'listing_type',
                                    $slug => 'slug',
                                    $term => $taxTerm,
                                )),                               
                                   
                $queryTax2 => array(
                                array(
                                    $tax => 'location',
                                    $slug => 'slug',
                                    $term => $taxTerm,
                                )),
               
               
                        )); 
                        while ( have_posts() ) : the_post();
                        $image_id = get_post_thumbnail_id();
                        $image_url = wp_get_attachment_image_src($image_id,'medium', true);   
                        $price = number_format(get_post_meta(get_the_ID(), '_general_nt_logo', true));
                        $image = str_replace("-".$image_url[1]."x".$image_url[2], "", $image_url[0]);
                        $featured = get_post_meta(get_the_ID(), 'boat-featured', true); 
                        echo '
                        <li>
                            <a href="'.get_permalink().'"><img src="'.ARURL.'/admin/thumb.php?src='.$image.'&w='.$nodeWidth.'&h='.$nodeHeight.'&q=100">
                            <div class="galDiv">
                                <div class="boatTitle">'.get_the_title().'</div>                       
                                <div class="boatPrice">'.currency ().$price.'</div>
                                <div class="boatPower"> '.get_post_meta(get_the_ID(), '_map_ar_address', true).'</div>
                            </div>
                            </a>
                        </li>';
                       
                        endwhile;  wp_reset_postdata();
                       
                echo '</div></div>';             
                echo emm_paginate();   
    }
    
    [php]
    PHP:
     
    lew1s666, Oct 14, 2014 IP
  7. lew1s666

    lew1s666 Member

    Messages:
    101
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    30
    #7
    can you somebody help with the taxonomy ?
     
    lew1s666, Oct 15, 2014 IP
  8. lew1s666

    lew1s666 Member

    Messages:
    101
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    30
    #8
    solved!
     
    lew1s666, Oct 15, 2014 IP
    PoPSiCLe likes this.