Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question
    
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 '11 at 16:35
add comment

2 Answers

up vote 1 down vote accepted

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;
}
share|improve this answer
add comment

Give a look at this plugin: Search Everything

share|improve this answer
    
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 '11 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 '11 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 '11 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 '11 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 '11 at 14:13
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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