Please help me with SQL custom search
-
I’m doing a search query that must search in the post meta values, that are stored in postmeta table. I have the same ID on both tables(I mean the same ID for each post) and want to include postmeta “meta_key” and “meta_value” in searched fields, as in the following code: (I hope you understand what I want)
SELECT post_id, meta_key, meta_value FROM $wpdb->postmeta , (SELECT * FROM $wpdb->posts WHERE NOT wpdb->posts.post_status = 'inherit' AND (wpdb->posts.post_type = 'page' OR wpdb->posts.post_type = 'post') AND (wpdb->posts.post_content LIKE '%".$term."%' OR wpdb->posts.post_name LIKE '%".$term."%' OR $wpdb->postmeta.meta_value LIKE '%".$term."%') ORDER BY wpdb->posts.post_title ASC) WHERE $wpdb->postmeta.post_id = $wpdb->posts.ID
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
The topic ‘Please help me with SQL custom search’ is closed to new replies.