繁体   English   中英

Wordpress-如何使用下拉选择器更改搜索值?

[英]Wordpress - How to change search value using a drop down selector?

就像标题中的Im希望使用选择下拉列表在正常的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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM