简体   繁体   English

如何在没有WP_Query'的情况下搜索帖子的'标题','内容'和'meta_query'?

[英]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'. 我在wordpress中编写了一个搜索查询,搜索'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? 我可以使用WP_Query的'post'和'meta_query'相关参数与'OR'结合使用,而不是使用WP_Query Search的参数,以便搜索查询通过仅传递WP_Query的相关参数来匹配'post_title'和'post_content'? OR is there a way to write query manually with $wpdb like below: 或者有没有办法用$ wpdb手动编写查询,如下所示:

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: 我收到以下MySql结果查询:

  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%'

Use custom query in following way : 以下列方式使用自定义查询:

SELECT * FROM `wp_posts` wp 
    INNER JOIN `wp_postmeta` wm ON (wm.`post_id` = wp.`ID`) 
        WHERE wp.`post_status` IN ('$status_array') 
        AND wp.`post_type`='messages'
        AND (wp.`post_title` LIKE '%$keyword%' OR 
wp.`post_content` LIKE '%$keyword%') 
        AND wm.`meta_key` = 'my_meta_key' 
        AND wm.`meta_value` LIKE '%$keyword%'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM