【问题标题】:Wordpress search shows no resultsWordpress 搜索没有结果
【发布时间】:2018-03-11 02:35:20
【问题描述】:

我又遇到了一个“wtf”问题。我不明白为什么我的搜索表单没有显示结果。看到这个网页:http://sindlar.cz/exemplum/?lang=en

标题中有get_search_form()。我还创建了 searchform.php 和 search.php。见search.php:

    <section id="primary" class="content-area">
        <div id="content" class="site-content" role="main">

        <?php if ( have_posts() ) : ?>

            <header class="page-header">
                <h1 class="page-title"><?php printf( __( 'Search Results for: %s', 'shape' ), '<span>' . get_search_query() . '</span>' ); ?></h1>
            </header><!-- .page-header -->

            <?php shape_content_nav(); ?>

            <?php /* Start the Loop */ ?>
            <?php while ( have_posts() ) : the_post(); ?>

                <?php get_template_part( 'content', 'search' ); ?>

            <?php endwhile; ?>

            <?php shape_content_nav( 'nav-below' ); ?>

        <?php else : ?>

            <?php get_template_part( 'no-results', 'search' ); ?>

        <?php endif; ?>

        </div><!-- #content .site-content -->
    </section><!-- #primary .content-area -->

点击搜索按钮后打开搜索页面,但没有结果。也许数据库有什么问题吗?你有什么想法?我应该在function.php中添加一些东西吗?

我还注意到搜索网站的实际内容和虚构的词之间存在差异。例如,如果您键入“关于我们”(这是我网站中的实际页面),它将显示 search.php 但没有结果。另一方面,如果您输入“Big truck”或“fsdgwdhs”(这是我编的),它会发回除 search.php 之外的其他页面。所以我认为 wordpress 可能知道有一些结果,但它没有显示出来。我不知道。

谁能帮帮我?

谢谢!

【问题讨论】:

  • 如果您认为问题可能出在结果的显示方式上,请在此处包含您的代码:get_template_part( 'content', 'search' )

标签: wordpress search search-form


【解决方案1】:

请按照以下步骤解决 wordpress 损坏的搜索

以下是解决搜索问题的方法:

Via FTP/Cpanel go to wp-content - themes - theme name you are using - functions.
Open theme-functions.php in a text editor.
Replace with the code below    

function gt_search_filter($query) {
if ($query->is_search) {
$query->set('post_type', 'post');
}
return $query;
}

add_filter('pre_get_posts','gt_search_filter');
*/

【讨论】:

  • 我将您的代码添加到我的主题文件夹中的functions.php中,但没有发生任何事情... :(您还有其他想法吗?
  • 我认为一定是插件导致了问题,请禁用某些插件或将插件文件夹更改为 plugin1 尝试看看它是否有效。如果这不起作用,请将您的主题更改为另一个主题以进行故障排除。希望这会有所帮助
  • 没什么用,我开始认为这一定是超自然现象:/
【解决方案2】:
<section id="primary" class="site-content">
    <div id="content" role="main">

    <?php if ( have_posts() ) : ?>

        <header class="page-header">
            <h1 class="page-title"><?php printf( __( 'Search Results for: %s', 'twentytwelve' ), '<span>' . get_search_query() . '</span>' ); ?></h1>
        </header>

        <?php twentytwelve_content_nav( 'nav-above' ); ?>

        <?php /* Start the Loop */ ?>
        <?php while ( have_posts() ) : the_post(); ?>
            <?php get_template_part( 'content', get_post_format() ); ?>
        <?php endwhile; ?>

        <?php twentytwelve_content_nav( 'nav-below' ); ?>

    <?php else : ?>

        <article id="post-0" class="post no-results not-found">
            <header class="entry-header">
                <h1 class="entry-title"><?php _e( 'Nothing Found', 'twentytwelve' ); ?></h1>
            </header>

            <div class="entry-content">
                <p><?php _e( 'Sorry, but nothing matched your search criteria. Please try again with some different keywords.', 'twentytwelve' ); ?></p>
                <?php get_search_form(); ?>
            </div><!-- .entry-content -->
        </article><!-- #post-0 -->

    <?php endif; ?>

    </div><!-- #content -->
</section><!-- #primary -->

将此代码与您的类和 CSS 一起放入 search.php 文件中

【讨论】:

  • 这要求主题为twentytwelve。这不是一个很好的建议。请解释您的建议以及原因。
猜你喜欢
  • 2012-03-30
  • 1970-01-01
  • 1970-01-01
  • 2010-10-28
  • 1970-01-01
  • 1970-01-01
  • 2013-12-18
  • 2017-04-02
相关资源
最近更新 更多