0
我正在爲我的自定義帖子撰寫搜索查詢。我正在使用WP_Query的搜索參數,因此它必須搜索'post_title'&'post_content',但它僅搜索'post_title',而不搜索'post_content'。下面是我的代碼:爲什麼WP_Query的's'=>'keyword'只搜索'post_title',爲什麼不'post_content'?
$institute_name = get_user_meta($user_ID, 'inistitute_name', true);
add_filter('posts_where' , array($this,'posts_where'));
$paged = (get_query_var('page')) ? get_query_var('page') : 1;
$args = array(
'post_type' => 'mypost',
array('s' => $keyword),
'meta_query' => array (
array (
'key' => 'inistitute_name',
'value' => array ($institute_name),
'compare' => 'IN'
)
),
'posts_per_page' => -1,
'paged' => $paged,
'post_status' => 'publish',
);
$the_query = new WP_Query($args);
remove_filter('posts_where', array($this,'posts_where'));
echo "<pre>";
print_r($the_query);
echo "</pre>";
如果我打印的結果,那麼我收到查詢象下面這樣:
SELECT wp_dxwe_posts.* FROM wp_dxwe_posts INNER JOIN wp_dxwe_postmeta ON
(wp_dxwe_posts.ID = wp_dxwe_postmeta.post_id) WHERE 1=1 AND
((wp_dxwe_postmeta.meta_key = 'inistitute_name' AND
CAST(wp_dxwe_postmeta.meta_value AS CHAR) IN ('ITeLearn')))
AND wp_dxwe_posts.post_type = 'mypost' AND ((wp_dxwe_posts.post_status = 'publish'))
AND post_title LIKE '%launch%' GROUP BY wp_dxwe_posts.ID
ORDER BY wp_dxwe_posts.post_date DESC
正如我說,這是隻有「POST_TITLE」工作正常,但爲什麼它是不爲'post_content'工作。任何人都可以告訴我這段代碼有什麼問題嗎?提前致謝。
嗯..首先,感謝您的快速回復。正如我所說的,只有'post_title'正在工作,如果我嘗試使用其他標題,那麼並不總是有效,那麼結果並不會顯示。如果是這樣,那麼你能告訴我什麼是解決方案? –