Wordpress search shows no results

Hynek Kaplan picture Hynek Kaplan · Sep 29, 2017 · Viewed 8.2k times · Source

I have one of those "wtf" problems again. I can't figure why my search form shows no result. See this webpage: http://sindlar.cz/exemplum/?lang=en

There is get_search_form() in the header. I also created searchform.php and search.php. See the 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 -->

The searchpage is opened after clicking on the search button but there are no results. Maybe is there any problem with database or anything? Do you have any ideas? Should I add something into function.php?

I also noticed that there is difference between searching actual content of the websites and made-up words. For example if you type "About us" (which is actual page in my websites), it will show the search.php but no results on it. On the other hand if you type "Big truck" or "fsdgwdhs" (which I made up), it will send back other page than search.php. So I think that wordpress maybe know that there are some results but it does not show them. I do not know.

Could anyone help me?

Thanks!

Answer

SUNNY ADEFUNFUN picture SUNNY ADEFUNFUN · Sep 29, 2017

please follow the procedure below to resolve wordpress broken search

Here is how to fix the search problem:

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');
*/