最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Standard Wordpress Search does not workSearch-results are not displayedCustom template

programmeradmin3浏览0评论

My search-results are not displayed. Instead searches show a 404. See / for testing. Can someone help?

What did I do?

  1. I implemented the standard WP-search using get_search_form(). This worked fine, as you can see on the page.
  2. I added the search.php and searchform.php in the root-folder of the template. Those phps came from the twentyseventeen-template of WP, as I am using a custom template and the files have been missing.

    The searchform-layout changed accordingly.

Unfortuntately, the search.php seems to be inactive in a way. Everytime, entering a search, delivers a 404.

Here the code of the search.php:

<get_header(); ?>

<div class="wrap">

    <header class="page-header">
        <?php if ( have_posts() ) : ?>
            <h1 class="page-title"><?php printf( __( 'Search Results for: %s', 'twentyseventeen' ), '<span>' . get_search_query() . '</span>' ); ?></h1>
        <?php else : ?>
            <h1 class="page-title"><?php _e( 'Nothing Found', 'twentyseventeen' ); ?></h1>
        <?php endif; ?>
    </header><!-- .page-header -->

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

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

                /**
                 * Run the loop for the search to output the results.
                 * If you want to overload this in a child theme then include a file
                 * called content-search.php and that will be used instead.
                 */
                get_template_part( 'template-parts/content', 'search' );

            endwhile; // End of the loop.

            the_posts_pagination(
                array(
                    'prev_text'          => twentyseventeen_get_svg( array( 'icon' => 'arrow-left' ) ) . '<span class="screen-reader-text">' . __( 'Previous page', 'twentyseventeen' ) . '</span>',
                    'next_text'          => '<span class="screen-reader-text">' . __( 'Next page', 'twentyseventeen' ) . '</span>' . twentyseventeen_get_svg( array( 'icon' => 'arrow-right' ) ),
                    'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'twentyseventeen' ) . ' </span>',
                )
            );

        else :
            ?>

            <p><?php _e( 'Sorry, but nothing matched your search terms. Please try again with some different keywords.', 'twentyseventeen' ); ?></p>
            <?php
                get_search_form();

        endif;
        ?>

        </main><!-- #main -->
    </div><!-- #primary -->
    <?php //get_sidebar(); ?>
</div><!-- .wrap -->

<?php
get_footer();

And here the code for the searchform.php:

<?php
/**
 * Template for displaying search forms in Twenty Seventeen
 *
 * @package WordPress
 * @subpackage Twenty_Seventeen
 * @since 1.0
 * @version 1.0
 */

?>

<?php $unique_id = esc_attr( twentyseventeen_unique_id( 'search-form-' ) ); ?>

<form role="search" method="get" class="search-form" action="<?php echo esc_url( home_url( '/' ) ); ?>">
    <label for="<?php echo $unique_id; ?>">
        <span class="screen-reader-text"><?php echo _x( 'Search for:', 'label', 'twentyseventeen' ); ?></span>
    </label>
    <input type="search" id="<?php echo $unique_id; ?>" class="search-field" placeholder="<?php echo esc_attr_x( 'Search &hellip;', 'placeholder', 'twentyseventeen' ); ?>" value="<?php echo get_search_query(); ?>" name="s" />
</form>

Appreciate any hint.

Best, Max

My search-results are not displayed. Instead searches show a 404. See https://startupsagainstcorona/solutions/ for testing. Can someone help?

What did I do?

  1. I implemented the standard WP-search using get_search_form(). This worked fine, as you can see on the page.
  2. I added the search.php and searchform.php in the root-folder of the template. Those phps came from the twentyseventeen-template of WP, as I am using a custom template and the files have been missing.

    The searchform-layout changed accordingly.

Unfortuntately, the search.php seems to be inactive in a way. Everytime, entering a search, delivers a 404.

Here the code of the search.php:

<get_header(); ?>

<div class="wrap">

    <header class="page-header">
        <?php if ( have_posts() ) : ?>
            <h1 class="page-title"><?php printf( __( 'Search Results for: %s', 'twentyseventeen' ), '<span>' . get_search_query() . '</span>' ); ?></h1>
        <?php else : ?>
            <h1 class="page-title"><?php _e( 'Nothing Found', 'twentyseventeen' ); ?></h1>
        <?php endif; ?>
    </header><!-- .page-header -->

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

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

                /**
                 * Run the loop for the search to output the results.
                 * If you want to overload this in a child theme then include a file
                 * called content-search.php and that will be used instead.
                 */
                get_template_part( 'template-parts/content', 'search' );

            endwhile; // End of the loop.

            the_posts_pagination(
                array(
                    'prev_text'          => twentyseventeen_get_svg( array( 'icon' => 'arrow-left' ) ) . '<span class="screen-reader-text">' . __( 'Previous page', 'twentyseventeen' ) . '</span>',
                    'next_text'          => '<span class="screen-reader-text">' . __( 'Next page', 'twentyseventeen' ) . '</span>' . twentyseventeen_get_svg( array( 'icon' => 'arrow-right' ) ),
                    'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'twentyseventeen' ) . ' </span>',
                )
            );

        else :
            ?>

            <p><?php _e( 'Sorry, but nothing matched your search terms. Please try again with some different keywords.', 'twentyseventeen' ); ?></p>
            <?php
                get_search_form();

        endif;
        ?>

        </main><!-- #main -->
    </div><!-- #primary -->
    <?php //get_sidebar(); ?>
</div><!-- .wrap -->

<?php
get_footer();

And here the code for the searchform.php:

<?php
/**
 * Template for displaying search forms in Twenty Seventeen
 *
 * @package WordPress
 * @subpackage Twenty_Seventeen
 * @since 1.0
 * @version 1.0
 */

?>

<?php $unique_id = esc_attr( twentyseventeen_unique_id( 'search-form-' ) ); ?>

<form role="search" method="get" class="search-form" action="<?php echo esc_url( home_url( '/' ) ); ?>">
    <label for="<?php echo $unique_id; ?>">
        <span class="screen-reader-text"><?php echo _x( 'Search for:', 'label', 'twentyseventeen' ); ?></span>
    </label>
    <input type="search" id="<?php echo $unique_id; ?>" class="search-field" placeholder="<?php echo esc_attr_x( 'Search &hellip;', 'placeholder', 'twentyseventeen' ); ?>" value="<?php echo get_search_query(); ?>" name="s" />
</form>

Appreciate any hint.

Best, Max

Share Improve this question asked Apr 2, 2020 at 12:10 Max MarquartMax Marquart 132 bronze badges 3
  • The action field of the form is https://startupsagainstcorona/, shouldn't that be https://startupsagainstcorona/solutions/? – Jos Commented Apr 2, 2020 at 12:28
  • Great hint! That was the solution! Changed it and it works :):) Thanks Jos!! – Max Marquart Commented Apr 2, 2020 at 12:32
  • Please allow me to state that as an answer. – Jos Commented Apr 2, 2020 at 12:35
Add a comment  | 

2 Answers 2

Reset to default 0

The action field of the search form refers to https://startupsagainstcorona, which is the root of the web server.

However, apparently Wordpress is installed at https://startupsagainstcorona/solutions, which is where the action field should refer to.

Can you try flushing your permalinks. This can be done by visiting the Permalinks under settings and hitting 'Save Changes'

发布评论

评论列表(0)

  1. 暂无评论