2014-01-05 228 views
0

我想在搜索欄中選擇所有搜索和自定義帖子類型。我已經完成了自定義搜索後,但是當我搜索所有然後出現錯誤,而不是working.Please看到圖像和代碼。 enter image description here在wordpress中自定義搜索所有和自定義帖子

搜索正在爲自定義帖子類型工作。但是,當我搜索所有,然後顯示錯誤。請參閱下面我的代碼。

function mySearchFilter($query){$post_type = $_GET['searchfrom']; 
if($post_type != 'all') 
{ 
    if ($query->is_search) 
    { 
     if (!empty($post_type)) { 
      $query->set('post_type', $post_type); 
     } 
    } 
} 
else 
{ 
    $query->set(); 
} 

return $query;} 

add_filter('pre_get_posts','mySearchFilter');

請讓我知道其他條件。

回答

2
function mySearchFilter($query){ 
$post_type = $_GET['searchfrom']; 
if($post_type != 'all') 
{ 
    if ($query->is_search()) 
    { 
     if (!empty($post_type)) { 
      $query->set('post_type', $post_type); 
     } 
    } 
} 

return $query; 
} 
add_filter('pre_get_posts','mySearchFilter'); 
相關問題