繁体   English   中英

Wordpress自定义帖子类型搜索结果页面

[英]Wordpress custom post type search results page

我设置了一个自定义搜索表单来搜索和显示我的自定义帖子类型的结果。 表格是:

<form class="search-form" action="<?php echo home_url( '/' ); ?>">
  <input type="search" name="s" placeholder="Search&hellip;">
  <input type="hidden" name="post_type" value="resource-library">  
  <input type="submit" value="Search">
</form>

在我的search.php中,如果内容类型是资源库,我想将人们引导到名为search-resource-library.php的自定义搜索php文件。 所以我把它放在search.php页面的顶部:

<?php
// store the post type from the URL string
$post_type = $_GET['post_type'];
// check to see if there was a post type in the
// URL string and if a results template for that
// post type actually exists
if ( isset( $post_type ) && locate_template( 'search-' . $post_type . '.php' ) ) {
  // if so, load that template
  get_template_part( 'search', $post_type );

  // and then exit out
  exit;
}
?>

我得到了正在做的事情,但我似乎无法从搜索表单html中设置的URL字符串中存储帖子类型。

有任何想法吗?

我发现了这个问题。 我的原始代码和方法是正确的。 由于安装了名为“Nice Search”的插件,因此未从搜索表单传递url参数。 此插件将?s =查询搜索重定向到/ search / query,并将%20转换为+。

暂无
暂无

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

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