自定义搜索WordPress表单

自定义搜索WordPress表单,wordpress,forms,search,conditional-statements,Wordpress,Forms,Search,Conditional Statements,.嗨,伙计们 如何执行以下代码: If ID search form == book {The Post excluded from the search} else {excluded a custom post type "book"} 我的搜寻表格如下: 第一 <form id="book" > it's a custom post type 这是一种自定义的帖子类型 第二 <form id="post" > //It's defau

.嗨,伙计们

如何执行以下代码:

 If    ID search form == book 
   {The Post excluded from the search} 
else 
   {excluded a custom post type "book"}
我的搜寻表格如下: 第一

<form id="book" > it's a custom post type
这是一种自定义的帖子类型
第二

<form id="post" > //It's default Post type WordPress
//它是默认的Post类型WordPress

我可以这样做吗?

将此代码放在function.php文件中

它将从post type book和post中搜索内容

function filter_search($query) {
if ($query->is_search) {
$query->set('post_type', array('post', 'book'));
};
return $query;
};
add_filter('pre_get_posts', 'filter_search');

将此代码放在function.php文件中

它将从post type book和post中搜索内容

function filter_search($query) {
if ($query->is_search) {
$query->set('post_type', array('post', 'book'));
};
return $query;
};
add_filter('pre_get_posts', 'filter_search');

非常感谢您的回复。但不幸的是,它没有成功。看来我还没有解释我有两种形式的搜索:第一:我只想找一本书,当然,有一个特别的主题。另一个是看所有没有书的网站。如下图所示。非常感谢您的回复。但不幸的是,它没有成功。看来我还没有解释我有两种形式的搜索:第一:我只想找一本书,当然,有一个特别的主题。另一个是看所有没有书的网站。如下图所示。