Title: Custom search query
Last modified: August 21, 2016

---

# Custom search query

 *  [sasa2209](https://wordpress.org/support/users/sasa2209/)
 * (@sasa2209)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/custom-search-query/)
 * Hi
 * I need help with creating custom search query. Here is the form code
 * <form role=”search” method=”get” class=”search-form” action=”<?php echo home_url(‘/’);?
   >/search-results”>
 * <div class=”search_jobs”>
    <?php do_action( ‘job_manager_job_filters_search_jobs_start’,
   $atts ); ?>
 * <div class=”item”>
    <label for=”search_keywords”><?php _e( ‘Keywords’, ‘wp-job-
   manager’ ); ?></label> <input type=”text” name=”search_keyword” id=”search_keyword”
   placeholder=”<?php _e( ‘All Jobs’, ‘wp-job-manager’ ); ?>” value=”<?php echo 
   esc_attr( $keywords ); ?>” /> </div>
 * <div class=”item”>
    <label for=”search_location”><?php _e( ‘Location’, ‘wp-job-
   manager’ ); ?></label> <input type=”text” name=”location” id=”search_location”
   placeholder=”<?php _e( ‘Any Location’, ‘wp-job-manager’ ); ?>” value=”<?php echo
   esc_attr( $location ); ?>” /> </div>
 * <div class=”item”>
    <label for=”search_categories”><?php _e( ‘Category’, ‘wp-
   job-manager’ ); ?></label> <?php wp_dropdown_categories( array( ‘taxonomy’ =>‘
   job_listing_category’, ‘hierarchical’ => 1, ‘show_option_all’ => __( ‘All Job
   Categories’, ‘wp-job-manager’ ), ‘name’ => ‘search_categories’, ‘orderby’ => ‘
   name’ ) ); ?> </div>
 * <div class=”search-s”>
    <input type=”submit” class=”search-submit” value=”Search”/
   > </div> </div> </form>
 * And here is query code
 * <?php
    $s_key = $_GET[‘search_keywords’]; $s_loc = $_GET[‘search_location’]; 
   $s_cat = $_GET[‘search_categories’];
 * $query = “SELECT * FROM ‘wp_posts’ WHERE ‘status’=1”;
 * if(isset($s_key) && !empty($s_key))
    { $query.= ” AND ‘post_content’ LIKE ‘”.
   $s_key.”‘”; } if(isset($s_loc) && !empty($s_loc)) { $query.= ” AND ‘meta_value’
   LIKE ‘”.$s_loc.”‘”; } if(isset($s_cat) && !empty($s_cat)) { $query.= ” AND ‘job_listing_category’
   LIKE ‘”.$s_cat.”‘”; }
 * ?>
 * <?php if( have_posts() ): ?>
    -  <?php while ( have_posts() ) : the_post(); ?>
    - 
    - <?php endwhile; ?>
 * <?php endif; ?>
 * <?php wp_reset_query(); ?>
 * Any help with this would be appreciated.
 * Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [webtegrity](https://wordpress.org/support/users/webtegrity/)
 * (@webtegrity)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/custom-search-query/#post-5078243)
 * This is the best plugin that we’ve found that allows you to customize your search
   queries.
 * [https://wordpress.org/plugins/relevanssi/](https://wordpress.org/plugins/relevanssi/)
 * What are you exactly trying to allow or disallow in the search function?
 *  [kevinhisko](https://wordpress.org/support/users/kevinhisko/)
 * (@kevinhisko)
 * [11 years, 12 months ago](https://wordpress.org/support/topic/custom-search-query/#post-5078469)
 * I have a simliar proble. If users enter a category (job_type) into keyword_search
   input nothing appears in the results. Is there a way to include categories with
   the query?

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Custom search query’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 3 participants
 * Last reply from: [kevinhisko](https://wordpress.org/support/users/kevinhisko/)
 * Last activity: [11 years, 12 months ago](https://wordpress.org/support/topic/custom-search-query/#post-5078469)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
