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.

Need Support for Developing WordPress Custom Search?

Discussion in 'WordPress' started by Designer Ashok, Mar 23, 2015.

  1. #1
    Hello WordPress Developers,
    I am currently developing a website with WordPress software. I know how to develop a WordPress theme but i am getting problem in developing the custom search engine for this website because i am not much experienced guy. So, i am expecting help from you and it is very important to me.

    I am planning to create a search engine which consists of two fields.
    1. Field to Enter "Category Name"
    2. Select Field to Choose "One of the Options (Taxonomy)"
    and Finally Search Button.

    I have done some research in Internet and finally found some code in wordpress forum.
    https://wordpress.org/support/topic/search-form-with-custom-taxonomy-dropdown?replies=7#post-1928248

    The following code is well working in my site and it generates search form.

    <form role="search" method="get" id="searchform" action="<?php echo home_url( '/' ); ?>">
      <div>
    <input type="text" value="Enter Your City" onfocus="this.value=''" name="category_name">
    
    <?php
    function get_terms_dropdown($taxonomies, $args){
        $myterms = get_terms($taxonomies, $args);
        $optionname = "technician";
        $emptyvalue = "";
        $output ="<select name='".$optionname."'><option selected='".$selected."' value='".$emptyvalue."'>Choose Technician</option>'";
    
        foreach($myterms as $term){
            $term_taxonomy=$term->technis; //CHANGE ME
            $term_slug=$term->slug;
            $term_name =$term->name;
            $link = $term_slug;
            $output .="<option name='".$link."' value='".$link."'>".$term_name."</option>";
        }
        $output .="</select>";
    return $output;
    }
    
    $taxonomies = array('technis'); // CHANGE ME
    $args = array('order'=>'ASC','hide_empty'=>true);
    echo get_terms_dropdown($taxonomies, $args);
    
    ?>
    
    <input type="submit" id="searchsubmit" value="Search" />
    </div>
    Code (markup):
    I have attached search form in the attachment. It is generating more options from taxonomy in the select field without any doubt but my wordpress site is unable to generate the search results. I am displaying the code in the search.php below.

    <?php get_header(); ?>
    
    <?php
    global $query_string;
    $termslug = $_GET['technician'];
    ?>
    
    <h2>Search Results For: <span style="font-weight: normal"><em><?php the_search_query(); ?></em></span></h2>
    
    <?php
    
    if (empty($termslug)) {
        query_posts($query_string);
        if(have_posts()) : while(have_posts()) : the_post();
        endwhile; else:
        _e('Sorry, no listings matched your criteria or you forgot select a category.');
        endif;
    }
    
    if (!empty($termslug)) {
             query_posts(array('YOURTAXONOMY' => $termslug) );
        if(have_posts()) : while(have_posts()) : the_post();
        endwhile; else:
        _e('Sorry, no listings matched your criteria or you forgot select a category.');
        endif;
    }
    
    ?>
    
    <?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?>
    <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
    <?php endwhile; ?>
    <?php endif; ?>
    
    
    <?php get_footer(); ?>
    Code (markup):
    I am expecting support from only experienced wordpress experts.
     

    Attached Files:

    Designer Ashok, Mar 23, 2015 IP