【发布时间】:2018-01-08 18:54:42
【问题描述】:
我有一个自定义帖子类型“艺术家”。我的 3 位艺术家中的每一位都有单独的艺术家页面。我将我的默认 wordpress 搜索限制为仅在 functions.php 文件中使用它来搜索“艺术家”帖子类型。
function searchfilter($query) {
if ($query->is_search && !is_admin() ) {
$query->set('post_type',array('Artist'));
}
return $query;
}
add_filter('pre_get_posts','searchfilter');
现在,我如何确保如果我输入艺术家姓名,它会在艺术家页面而不是默认搜索页面上显示搜索结果。
例如,如果我在搜索框中输入 John,搜索结果应该会显示包含单词 John 的艺术家页面的所有内容。
这里是 search.php 代码
<?php
if ( have_posts() ) : ?>
<?php
/* Start the Loop */
while ( have_posts() ) : the_post();
/**
* Run the loop for the search to output the results.
* If you want to overload this in a child theme then include a file
* called content-search.php and that will be used instead.
*/
<?php the_title(); ?>
<?php the_content(); ?>
endwhile;
the_posts_navigation();
else :
get_template_part( 'template-parts/content', 'none' );
endif; ?>
【问题讨论】:
-
搜索结果将显示所有具有关键字的
artist页面,而不仅仅是一个艺术家页面。您只想显示一页吗?如果用户搜索两个艺术家页面中的关键字,您希望发生什么? -
嗨,阿米特,所以,如果我输入 John,它应该会显示所有页面上包含单词 John 的所有 div。如果单词 john 在两个页面上,它应该显示包含单词 John 的两个页面的所有 div。现在我正在获取包含单词 John 的所有页面的标题
标签: php wordpress advanced-custom-fields