问题描述
我有一个 php 代码,我想在其中根据 post_title
拉帖子.让我们假设 $keyword
是 chicago
或 Chicago
.
if ($keyword) {$query = new \WP_Query(['s' =>$关键字,'post_type' =>'abc-xyz','post_status' =>'发布']);} 别的 {$query = new \WP_Query(['post_type' =>'abc-xyz','post_status' =>'发布',//'ep_integrate' =>真的,'orderby' =>'标题','订单' =>'ASC']);}echo '';print_r($query->posts);echo '</pre>';//A线
当 $keyword
为 Chicago
或 chicago
时,A 行打印以下数组:
数组([0] =>WP_Post 对象([ID] =>280045[post_title] =>芝加哥)[1] =>WP_Post 对象([ID] =>680045[post_title] =>皮奥里亚)[2] =>WP_Post 对象([ID] =>180045[post_title] =>皮奥里亚)[3] =>WP_Post 对象([ID] =>880045[post_title] =>芝加哥)[4] =>WP_Post 对象([ID] =>180000[post_title] =>芝加哥))
我想知道为什么当 $keyword
是 chicago
或 post_title
Peoria
代码>芝加哥代码>.
正如@FluffyKitten 所指出的,默认的 Wordpress 搜索不仅限于帖子标题.它同时搜索 post_title
和 post_content
.
I have a php code in which I want to pull posts on the basis of post_title
. Let us suppose the $keyword
is chicago
or Chicago
.
if ($keyword) {
$query = new \WP_Query([
's' => $keyword,
'post_type' => 'abc-xyz',
'post_status' => 'publish'
]);
} else {
$query = new \WP_Query([
'post_type' => 'abc-xyz',
'post_status' => 'publish',
//'ep_integrate' => true,
'orderby' => 'title',
'order' => 'ASC'
]);
}
echo '<pre>'; print_r($query->posts); echo '</pre>'; // Line A
Line A prints the following array when $keyword
is Chicago
or chicago
:
Array
(
[0] => WP_Post Object
(
[ID] => 280045
[post_title] => Chicago
)
[1] => WP_Post Object
(
[ID] => 680045
[post_title] => Peoria
)
[2] => WP_Post Object
(
[ID] => 180045
[post_title] => Peoria
)
[3] => WP_Post Object
(
[ID] => 880045
[post_title] => Chicago
)
[4] => WP_Post Object
(
[ID] => 180000
[post_title] => Chicago
)
)
I am wondering why its pulling posts with the post_title
Peoria
when the $keyword
is chicago
or Chicago
.
As @FluffyKitten notes, the default Wordpress search is not limited to just the post title. It searches both post_title
and post_content
.
这篇关于's' =>$term, 不是在 wordpress/php 的 post_title 的基础上拉帖子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!