我试图在Wordpress中只按自定义帖子类型进行搜索。
在我的搜索表单中,我有:
<input type="hidden" name="post_type" value="customposttype" />
在我的函数文件中,我有: function template_chooser($template)
{
global $wp_query;
$post_type = get_query_var(\'post_type\');
if( $wp_query->is_search && $post_type == \'customposttype\' )
{
return locate_template(\'customposttype-search.php\');
}
return $template;
}
add_filter(\'template_include\', \'template_chooser\');
这让我找到了正确的搜索模板。然而,我仍然在实际的搜索结果中得到WordPress的所有结果。是否需要修改:<?php if( have_posts()){ ?>
<?php while( have_posts() ) : the_post(); ?>
...
在我的“customposttype search.php”中也是这样吗?