2013-06-24 261 views
0

在我的WordPress站点中,我需要两种类型的搜索基本wordpress搜索之一另一种是自定义search.both r分开。第一个是好的,但第二个是创建问题。在自定义搜索我必须搜索类别和关键字,这里的类别是custom_taxonomy,post类型也是自定义的post类型。 分类= FAQ组 post_type = FAQ项针对自定义帖子类型的自定义搜索

例如:如果任何一个搜索类别=澳大利亚和关键字=签证然后,它会显示有从FAQ模块签证关键字和澳大利亚类别中的所有职务。 我搜索它google.I想,我已经写自定义查询 预先感谢

回答

0

使用下面的代码实现这个

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'); 

我没有测试代码,但我希望它会对你有用。

+0

这行有语法错误$ where =“post_content Like%$ _ POST ['your-custom-serchtext']%”,$ where); – user1987095

+0

add_filter无法正常工作 – user1987095

+0

http://codex.wordpress.org/Plugin_API/Filter_Reference/posts_where – user1987095

相关问题