我需要在wordpress中自定义搜索,因此搜索也会在postmeta表中查找关键字。我把meta_query变量用于wp_query变量。对于wp_query对象,查询的输出如下:
SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts INNER JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id)
INNER JOIN wp_postmeta AS mt1 ON(wp_posts.ID = mt1.post_id) INNER JOIN wp_postmeta AS mt2 ON(wp_posts.ID = mt2.post_id)WHERE 1 = 1 AND wp_posts.post_parent = 0 AND(((wp_posts.post_title LIKE'%4422%')或(wp_posts.post_content LIKE'%4422%' )))和wp_posts.post_type ='wpsc-product'AND(wp_posts.post_status ='publish'或wp_posts.post_status ='private')AND((wp_postmeta.meta_key ='CAS#'AND CAST(wp_postmeta.meta_value AS CHAR) )喜欢'%4422%') 或(mt1.meta_key ='style'和CAST(mt1.meta_value AS CHAR)LIKE'%4422%') 或(mt2.meta_key ='打包'和CAST(mt2.meta_value AS CHAR)喜欢'%4422%'))GROUP BY wp_posts.ID ORDER BY wp_posts.post_title ASC LIMIT 0,75
现在的问题是,它正在寻找后期和后期postmeta table。如果关键字不在post_content或post_title中而不在meta字段中,则不会发生任何事情。
我需要这个来查看post_content,post_title&元字段因此它在任何这些中找到值,它将显示结果。现在它正在显示
答案 0 :(得分:0)
尝试以下代码:
wp_reset_query();
$args = array('ignore_sticky_posts' => 1,'meta_key'=> KEY_TO_SEARCH, 'meta_value'=>$search_value, 'post_type'=> 'post','orderby' => 'post_date','order' => 'DESC','post_status' => 'publish', 'posts_per_page' => $post_to_show);
query_posts($args);