【问题标题】:php query, work only one at timephp查询,一次只工作一个
【发布时间】:2017-10-22 05:45:07
【问题描述】:

我在我的 wp 网站中使用此 php filter 搜索框。 我知道这是错误的,因为过滤器只显示最后一个查询,我如何以两种查询的工作方式编写代码?

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

谢谢。

【问题讨论】:

    标签: php jquery wordpress filter


    【解决方案1】:

    您每次都在最后一个post_type 上设置$query,这当然是错误的。

    改成

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

    【讨论】:

    • 非常感谢!我是 php 的初学者,还没有想到使用数组!现在我学会了谢谢!
    猜你喜欢
    • 2023-03-20
    • 2014-11-04
    • 2013-09-26
    • 1970-01-01
    • 2013-07-30
    • 1970-01-01
    • 2011-09-16
    • 1970-01-01
    • 2017-01-06
    相关资源
    最近更新 更多