Custom Query for Search
I am creating a new ajax search functionality in my theme.
I want to search in a Custom Post Type and the search word should be compared with POST ID, POST NAME, POST SLUG, POST CONTENT, POST EXCERPT and also term of a (fixed) texonomy.
The Custom Post Type is “Property”
The Texonomy is “Locations”
So I have created a query:
SELECT * FROM $wpdb->posts INNER JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id) INNER JOIN $wpdb->terms ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->terms.term_id) WHERE $wpdb->posts.post_status = 'publish' AND $wpdb->posts.post_type = 'properties' AND ( $wpdb->terms.name LIKE '%$q%' OR $wpdb->posts.ID LIKE '$q' OR $wpdb->posts.post_content LIKE '%$q%' OR $wpdb->posts.post_title LIKE '%$q%' OR $wpdb->posts.post_excerpt LIKE '%$q%' OR $wpdb->posts.post_name LIKE '%$q%' ) AND $wpdb->posts.post_status = 'publish'
This is working but the result is list is repeating properties.
So anyone help me to correct this query?
- The topic ‘Custom Query for Search’ is closed to new replies.