php - How can I search for post's 'title','content'&'meta_query' without WP_Query 's'?
I have written a search query in wordpress that searches for 'post_title', 'post_content' & 'meta_query'. Instead of using WP_Query Search 's' parameter, can I use WP_Query's 'post' & 'meta_query' related parameters combine with 'OR' so that search query matches the 'post_title' and 'post_content' by passing only concerned parameters of WP_Query? OR is there a way to write query manually with $wpdb like below:
global $wpdb;
$query= "SELECT wp_dxwe_posts.* FROM `wp_posts` WHERE
(wp_posts.post_status IN ('$status_array') AND
wp_posts.post_type='messages') AND
(wp_posts.post_title LIKE '%$keyword%' OR wp_posts.post_content
LIKE '%$keyword%') AND ( wp_postmeta.meta_key == 'my_meta_key' AND
wp_postmeta.meta_value LIKE '%$keyword%') ";
$my_query = $wpdb->get_results($query);
Can any one please tell me how? Thanks in advance.
I am getting the following MySql result query:
SELECT * FROM `wp_dxwe_posts` wp
INNER JOIN `wp_dxwe_postmeta` wm ON (wm.`post_id` = wp.`ID`)
WHERE wp.`post_status` IN ('publish,pending,draft')
AND wp.`post_type`='messages'
AND (wp.`post_title` LIKE '%prasad%' OR
wp.`post_content` LIKE '%prasad%')
AND wm.`meta_key` = 'inistitute_name'
AND wm.`meta_value` LIKE '%some_institute_name%'
Answer
Solution:
Use custom query in following way :