WP Search页面仅显示搜索的关键字,没有结果

时间:2015-08-13 03:03:52

标签: wordpress search

我在这里疯了。我是WP的新手,但已阅读了大量的手抄本和许多WP开发书籍,我觉得我对代码的工作方式有了不错的理解。到目前为止,我已经能够解决我在创建自定义主题时遇到的每个问题,只需在网上搜索答案即可。我没有这个特别的问题,尽管有些相关。我尝试了推荐的方法,但对于我的情况,他们没有帮助。

这是问题所在。

我的标题右上角有一个自定义搜索栏。

我已加入get_search_form()

我使用了正确的代码,但堆栈溢出一直阻止它,所以我只是使用了一个简短的php get搜索表单代码演示这个问题的目的,以显示我所做的自定义搜索表单。

所有内容都非常有效,直到搜索结果通过我创建的搜索结果显示出来page.php。当您进行关键字搜索时,唯一显示的是:

Search Results For: "whatever you enter into the search box".

我专注于两个php文件,以便我的搜索工作。

以下是每个代码。

搜索-form.php的

<form method="get" class="has-form" action="<?php bloginfo('url'); ?>/">
<div class="row collapse">
<div class="large-8 small-9 columns">
<label class="hidden" for="s"><?php _e('Search:'); ?></label>
<input type="text" value="<?php the_search_query(); ?>" name="s" id="s" />

<input type="hidden" value="post" name="post_type" id="post_type" />

</div>
<div class="large-4 small-3 columns">
<input type="submit" id="searchsubmit" value="Search" />
</div>
</div>
</form>

以及search-page.php

<?php
/**
 * The template for displaying Search Results pages.
 */

get_header(); ?>


    <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( 'nav-above' ); ?>

            <?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 -->

有人可以帮我弄清楚为什么在搜索完成时它只显示搜索到的内容而没有结果。我有大约6个测试帖子,甚至关键字“the”,“lorem”或“hello”都显示的结果不是搜索到的单词。

我错过了一大堆代码吗?我检索了我的代码并调整了一下以适应我的主题设计,但没有什么重要的......只是类名。

提前致谢。

此外,这是一个截图,以演示我在说什么。

enter image description here

0 个答案:

没有答案