【问题标题】:Customize Search WordPress Form自定义搜索 WordPress 表单
【发布时间】:2016-12-18 21:55:25
【问题描述】:

.大家好

如何执行以下代码:

 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

我可以这样做吗?

【问题讨论】:

    标签: wordpress forms search conditional-statements


    【解决方案1】:

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

    它将从帖子类型的书和帖子中搜索内容

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

    【讨论】:

    • 非常感谢您的回复。但不幸的是,它没有成功。看来我没有解释我的想法我有两种搜索形式: 第一:我想只找书,当然要有专门的主题。另一种是在没有书的情况下查看所有站点。如下图所示。
    • i.stack.imgur.com/KuC5f.jpg" width="800" height="600">
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-11-21
    • 2018-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-05
    相关资源
    最近更新 更多