• 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 endif; ?>

    <?php wp_reset_query(); ?>

    Any help with this would be appreciated.

    Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom search query’ is closed to new replies.