2

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

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

1
  • UPDATE: I feel like I am almost there but can anyone spot what I am doing wrong here: $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']."')";
    – Lee
    Jul 25, 2011 at 16:35

2 Answers 2

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;
}
1
  • how do you trigger these? Thanks, D.
    – v3nt
    Sep 11, 2020 at 14:24
0

Give a look at this plugin: Search Everything

6
  • Ye I have been looking at that but I can't figure out what bits i need for my serch as it is a seperate search and will not trigger the serch function in WordPress
    – Lee
    Jul 22, 2011 at 7:50
  • It does use the default wordpress search: "increases the ability of the default WordPress Search" and it says that it searches "Search Custom Taxonomies" and "Search Every Custom Field".
    – kevin
    Jul 22, 2011 at 14:06
  • The search I am using does nit use the built in search itis a search that filters the wp query
    – Lee
    Jul 23, 2011 at 17:20
  • Hmm understood, but did you try using the default search with this plugin? What kind of search are you using?
    – kevin
    Jul 24, 2011 at 0:38
  • The search everything plugin works fine for the wordpress search but i need to be able to do it for my own search which is for a job search for a particular custom post type with many different filters.
    – Lee
    Jul 25, 2011 at 14:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.