关于标题,我希望使用选择下拉列表在WordPress中创建搜索表单,以搜索正常的WordPress帖子以及自定义帖子类型。
普通帖子的外观不同,我有一个带有垂直缩略图的自定义帖子类型
我使用此功能计算出搜索结果
function template_chooser($template)
{
global $wp_query;
$post_type = get_query_var('post_type');
if( $wp_query->is_search && $post_type == 'gallery' )
{
return locate_template('taxonomy-gallery.php');
}
return $template;
}
add_filter('template_include', 'template_chooser');
但是我的问题在搜索表中
用于搜索默认WordPress帖子的默认搜索表单是此表单:
<div class="searchbox">
<form action="<?php echo home_url( '/' ); ?>" method="get"><button name="search" class="button">
<span></span></button>
<input type="text" id="s" name="s" value="" />
</form>
</div>
通过添加<input type="hidden" name="post_type" value="gallery" />
,我可以通过taxonomy-gallery.php获得图库的搜索结果
所以我最后的搜索表单代码是这个
<div class="searchbox">
<form action="<?php echo home_url( '/' ); ?>" method="get"><button name="search" class="button">
<span></span></button>
<input type="text" id="s" name="s" value="" />
<input type="hidden" name="post_type" value="gallery" />
</form>
</div>
但是我想在搜索输入中添加一个选择,使我可以选择要搜索的帖子或自定义帖子类型(图库)
例如,您可以查看此图像
选择下拉列表可以这样:
<select name="post_type" >
<option value="post">Posts</option>
<option value="gallery">Gallery</option>
</select>
此功能只能在标题或内容帖子/页面中搜索吗?