Php Wordpress WP_查询搜索标题和内容?

Php Wordpress WP_查询搜索标题和内容?,php,wordpress,Php,Wordpress,WP_Query()中的“s”参数是否仅搜索标题? 如何使其仅用于搜索内容? 如何使其同时搜索标题和内容?您无法按帖子内容筛选查询。您必须编写一个函数,在所有帖子中循环查找字段 啊,我找到了解决办法 function where_title_only($where_clause) { return ($where_clause." AND `post_title` LIKE '%".trim($_POST['k'])."%' ");

WP_Query()中的“s”参数是否仅搜索标题? 如何使其仅用于搜索内容?
如何使其同时搜索标题和内容?

您无法按帖子内容筛选查询。您必须编写一个函数,在所有帖子中循环查找字段

啊,我找到了解决办法

         function where_title_only($where_clause) {
                return ($where_clause." AND `post_title` LIKE '%".trim($_POST['k'])."%' ");
         }
         function where_desc_only($where_clause) {
                return ($where_clause." AND `post_content` LIKE '%".trim($_POST['k'])."%' ");
         }
         function where_both($where_clause) {
                return ($where_clause." AND (`post_title` LIKE '%".trim($_POST['k'])."%' "." OR `post_content` LIKE '%".trim($_POST['k'])."%' ) ");
         }

         if (trim($_POST['search_type']) == "title") {
                  add_filter("posts_where","where_title_only");
         }if (trim($_POST['search_type']) == "desc") {
                  add_filter("posts_where","where_desc_only");
         }else{
                  add_filter("posts_where","where_both");
         }

我计划使用post_搜索过滤器,但我在上没有看到任何文档。我很久以前读过一篇文章,这可以使用过滤器!我就是找不到信息。过滤器是一种引入自定义函数的方法,我在上面提到过,所以你的下一票是无效的。您的问题是如何使用WP_查询,而不是如何使用过滤器。你不必使用过滤器,除非你想修改WP_查询的功能,这也不是你的问题,我想这是值得的,因为它可能应该是一个注释。很高兴你找到了。书签:D