Relevanssi Wordpress搜索结果

时间:2018-02-16 04:29:32

标签: wordpress search relevanssi

我们有一个客户网站(http://hayball.com.au)运行Relevanssi Wordpress插件(https://www.relevanssi.com)。

客户已注意到搜索时未显示某些结果。例如,搜索“学习”一词应该显示包含“学习”作为搜索词的所有结果。虽然搜索词在标题中,但它没有显示名为“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插件。

非常感谢任何帮助或帮助。

谢谢, 戴恩

2 个答案:

答案 0 :(得分:0)

我使用Relevanssi已有几年但不是专家。如果我们的任何帖子中都存在搜索字词,我就没有找到搜索字词的情况。由于在搜索caulfield时找到了帖子,这意味着帖子已被编入索引。我在上面添加了一个帖子,其中包含您在上面提供的标题。当搜索&#34;学习或学习时,Relevansii返回了帖子。我可以重现帖子没有找到的唯一方法是添加&#34;学习&#34;到Relevanssi停止单词列表。确保它不在您的停用词列表中。在设置/索引/显示高级设置下有一个Relevanssi选项,用空格替换&符号。我测试了你的帖子标题用空格替换了&符号并再次保留了&符号。它被发现了两次。对不起,我无法提供更多帮助。

答案 1 :(得分:0)

事实证明,在我们的代理机构接手之前,该网站的前任开发人员忽略了在搜索结果中建立分页。所以它确实出现在第3页。哈哈。

感谢大家的帮助。

相关问题