I want to create a search that does:
- Search within my custom taxonomy - custom-tags
- search the post title
- search select meta field ?? dont know
- search with custom post type - easy part
I looked wordpress API but couldn't find any useful built in functions, i created a custom query below: there is bug here since it returns duplicate results sometime, maybe left join might be needed here.
this query searches for term and title only at moment, but i also want a meta field called cterm searched.
SELECT wp_posts.* FROM wp_posts, wp_term_relationships, wp_term_taxonomy, wp_terms WHERE (wp_terms.name LIKE '%car%' OR wp_posts.post_title LIKE '%car%') AND wp_posts.post_status = 'publish' AND wp_posts.post_type = 'posts_vch' AND wp_posts.ID = wp_term_relationships.object_id AND wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id AND wp_term_taxonomy.term_id = wp_terms.term_id GROUP BY wp_posts.ID LIMIT 1 ,50
above updated query, manage to remove duplicate result using
group by BUT another bug is that it does NIT bring POSTs with term "car".
Basically it only show posts that have the word "car" in the title but not in term/tag.