how to search in custom fields & custom taxonomy for custom search

I have a custom search which is a form that submits to the same page and uses wp_query to filter the results for a jobs site that I would also like the keyword search to also search in custom fields and a custom taxonomy but I am unsure how to use posts_join to do this.

I want to allow the user to type in the reference number into the keyword box and for it to search in all custom fields and the custom taxonomy but not filter the results as they won’t always match so if i search for a skill i dont want it to not return results if it doesnt match the skill custom field as the keyword maybe in the main description

Read More

does that make sense?

UPDATE:
I found this code: Include custom taxonomy term in search

But it doesnt work correctly for some reason rather than bringing back 11 results it is showing 114 so somethihng is not quite right Hover it is searching in the custom taxonomy so this is a starting point.

I just need it to search the custom taxonomy and custom fields but fix the amount of results

Related posts

Leave a Reply

2 comments

  1. Managed to figure it out by adapting that code from the link i posted:

    function atom_search_where($where){
    global $wpdb;
    if($_SESSION['js'] != '')
    $where .= "OR (t.name LIKE '%".trim($_SESSION['js'])."%' AND {$wpdb-    >posts}.post_status = 'publish')";
    $where .= "OR ($wpdb->postmeta.meta_key = '_job_ref' AND $wpdb->postmeta.meta_value = '".$_SESSION['js']."')";
    return $where;
    }
    
    function atom_search_join($join){
    global $wpdb;
    if($_SESSION['js'] != '')
    $join .= "LEFT JOIN {$wpdb->term_relationships} tr ON {$wpdb->posts}.ID = tr.object_id INNER JOIN {$wpdb->term_taxonomy} tt ON tt.term_taxonomy_id=tr.term_taxonomy_id INNER JOIN {$wpdb->terms} t ON t.term_id = tt.term_id";
    $join .= "LEFT JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id)";
    return $join;
    }