我们有一个运行 Relevanssi Wordpress 插件 ( https://www.relevanssi.com ) 的客户网站 ( http://hayball.com.au )。
客户注意到某些结果在搜索时不会出现。例如,搜索“学习”一词应显示包含“学习”作为搜索词的所有结果。即使搜索词在标题中,它也不会显示名为“Caulfield Grammar School, Masterplan & Learning Project”的项目。
如果您随后使用“caulfield”作为搜索词,则会显示该项目。这是在主题中显示搜索结果的代码。
<?php if (have_posts()): ?>
<ul>
<?php while (have_posts()) : the_post(); ?>
<?php
$posttype = get_post_type();
$link = '';
$readmore = '';
$excerpt = '';
if( $posttype == 'projects' ) {
$category = get_the_terms(get_the_ID(), 'sector');
$primaryCat = get_post_meta(get_the_ID(),'_yoast_wpseo_primary_sector',true);
if($primaryCat){
$category = null;
$primary = get_term($primaryCat, 'sector');
$category[] = $primary;
}
$link = '<a href="/projects/">' . $project . '</a>';
if($category) {
$link = $link . ' / <a href="/projects/#' . $category[0]->slug . '">' . $category[0]->name . '</a>';
}
$link = $link . ' / <a href="' . get_the_permalink() . '">' . get_the_title() . '</a>';
$readmore = get_the_permalink();
$excerpt = get_the_excerpt();
}
if( $posttype == 'news' ) {
$category = get_the_terms(get_the_ID(), 'category');
$link = '<a href="/news/">' . $exchange . '</a>';
if($category) {
$link = $link . ' / <a href="/news/#' . $category[0]->slug . '">' . $category[0]->name . '</a>';
}
$link = $link . ' / <a href="' . get_the_permalink() . '">' . get_the_title() . '</a>';
$readmore = get_the_permalink();
$excerpt = get_the_excerpt();
}
if( $posttype == 'award' ) {
$link = ''; //'<a href="/practice/awards/">Awards</a>';
$readmore = '/practice/awards/';
$excerpt = get_the_excerpt();
}
if( $posttype == 'person' ) {
$link = ''; //'<a href="/practice/people/">People</a>';
$readmore = '/practice/people/';
$excerpt = get_the_title();
}
if( $posttype == 'location' ) {
$link = ''; //'<a href="/contact/">Contact</a>';
$readmore = '/contact/';
$excerpt = get_field('address');
}
if( $posttype == 'page' ) {
$link = ''; //'<a href="' . get_the_permalink() . '">' . get_the_title() . '</a>';
$readmore = get_the_permalink();
}
?>
<li id="<?php echo get_the_ID(); ?>">
<div class="content">
<h4><?php the_title(); ?></h4>
<p class="link">
<?php echo $link; ?>
</p>
<p><?php echo $excerpt; ?></p>
<a href="<?php echo $readmore; ?>"><?php echo translation('read_more'); ?></a>
</div>
<?php if(wp_get_attachment_image_src( get_post_thumbnail_id(get_the_ID()), 'thumbnail' )) : ?>
<div class="image" style="background-image: url('<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id(get_the_ID()), 'thumbnail' ); echo $image[0]; ?>')"></div>
<?php endif; ?>
</li>
<?php endwhile; ?>
</ul>
<?php else: ?>
<p>
0 <?php echo translation('results'); ?>
</p>
<?php endif; ?>
我还被告知尝试将其添加到functions.php 似乎没有做任何事情。
function mjt_project_search( $query ) {
if ( $query->is_search ) {
$query->set( 'post_type', array( 'projects', 'news', 'award', 'person', 'location', 'page') );
$query->set( 'post_status', array( 'publish') );
}
return $query;}
add_filter( 'pre_get_posts', 'mjt_project_search' );`
当插件被禁用时,它会正确显示结果,但客户端需要所有搜索结果的高度相关性,因此使用 Relevanssi 插件。
任何帮助或帮助将不胜感激。
谢谢,戴恩