Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress 根据自定义帖子类型进行自定义搜索_Wordpress - Fatal编程技术网

Wordpress 根据自定义帖子类型进行自定义搜索

Wordpress 根据自定义帖子类型进行自定义搜索,wordpress,Wordpress,在我的wordpress网站中,我需要两种类型的搜索,一种是基本的wordpress搜索,另一种是自定义搜索。两者都是独立的。第一种是可以的,但第二种是产生问题。在自定义搜索中,我必须搜索类别和关键字,这里类别是自定义分类法,帖子类型也是自定义帖子类型。 分类法=常见问题组 发布类型=常见问题解答项目 示例:如果任何一个搜索类别=澳大利亚和关键字=visa,那么它将显示faq模块中包含visa关键字和澳大利亚类别的所有帖子。 我在谷歌上搜索过。我想,我已经编写了自定义查询 提前感谢使用以下代码实

在我的wordpress网站中,我需要两种类型的搜索,一种是基本的wordpress搜索,另一种是自定义搜索。两者都是独立的。第一种是可以的,但第二种是产生问题。在自定义搜索中,我必须搜索类别和关键字,这里类别是自定义分类法,帖子类型也是自定义帖子类型。 分类法=常见问题组 发布类型=常见问题解答项目

示例:如果任何一个搜索类别=澳大利亚和关键字=visa,那么它将显示faq模块中包含visa关键字和澳大利亚类别的所有帖子。 我在谷歌上搜索过。我想,我已经编写了自定义查询
提前感谢

使用以下代码实现此目的

function custom_search_where( $where )
{
    if(isset($_POST['your-custom-serchtext'])){
        $where = "post_content Like %$_POST['your-custom-serchtext']% ", $where );

    }
    return $where;
}

  $query = new WP_Query( array('post_type' => 'faq-item','tax_query' => array(
        array(
            'taxonomy' => 'faq-group',
            'field' => 'slug',
            'terms' => 'australia '
        )
    )) );
  add_filter('posts_where', 'custom_search_where' );

if ( $query->have_posts() ) {
    while ( $query->have_posts() ) {
        $query->the_post();
        echo '<li>' . get_the_title() . '</li>';
    }
} else {
    // no posts found
}

remove_filter( 'posts_where', 'custom_search_where' );
函数自定义搜索哪里($where)
{
如果(isset($_POST['your-custom-serchtext'])){
$where=“post\u内容,如%$\u post['your-custom-serchtext']%”,$where);
}
返回$where;
}
$query=新的WP\U查询(数组('post\U type'=>faq item','tax\U查询'=>array(
排列(
“分类法”=>“常见问题组”,
'字段'=>'段塞',
“术语”=>“澳大利亚”
)
)) );
添加_过滤器('posts_where','custom_search_where');
如果($query->have_posts()){
而($query->have_posts()){
$query->the_post();
回显“
  • ”。获取标题(); } }否则{ //没有找到帖子 } 删除_过滤器('posts_where'、'custom_search_where');

  • 我还没有测试过这段代码,但我希望它对您有用。

    这一行有语法错误$where=“post\u content Like%$\u post['your-custom-serchtext']%”,$where);