Support » Plugin: WP Job Manager » Cannot search for employer name

  • Resolved dnextreme88

    (@dnextreme88)


    The search results for my theme return no jobs if I search using the employer/company’s name (assuming it has a job). How do I make it so that I can display the job listings if I search using the employer name?

Viewing 1 replies (of 1 total)
  • Thread Starter dnextreme88

    (@dnextreme88)

    I found a solution for this, albeit modifying the SQL query when a search is made (after countless hours of searching). They should seriously update this plugin with better customization options and streamlined functions. Even the documentation is poorly written, no step-by-step instructions. For anyone who’s looking at the same solution as I do, use the function below and place this in your theme’s functions.php:

    function add_author_to_search($where) {
            global $wpdb;
            if( is_search() ) { // Check if a search is made
                $search = get_query_var('s');
    	    $like = '%' . $wpdb->esc_like( $search ) . '%';
    	    $query = $wpdb->prepare( "SELECT user_id FROM $wpdb->usermeta WHERE ( meta_key='first_name' AND lower(meta_value) LIKE '%%%s%%' ) OR ( meta_key='last_name' AND lower(meta_value) LIKE '%%%s%%' ) OR ( meta_key='_company_name' AND lower(meta_value) LIKE '%%%s%%' )", $search, $search, $search);
                $authorID = $wpdb->get_var( $query );
    
                if ($authorID) { // If a user_id matches a user
                    $where .= " OR " .$wpdb->posts. ".post_author = {$authorID} AND " .$wpdb->posts. ".post_name LIKE '" .$like. "'"; // Add to query of function: $GLOBALS[$WP_QUERY_VAR]->request
                }
             }
             return $where;
        }
    
    add_filter('posts_where','add_author_to_search');
Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.