首页 文章

Wordpress搜索没有显示任何结果

提问于
浏览
0

我又遇到了其中一个"wtf"问题 . 我无法理解为什么我的搜索表单没有显示结果 . 查看此网页:http://sindlar.cz/exemplum/?lang=en

Headers 中有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可能知道有一些结果,但它没有显示出来 . 我不知道 .

谁能帮助我?

谢谢!

2 回答

  • 0

    请按照以下步骤解决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');
    */
    
  • 1
    <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文件中

相关问题