[resolved] searching for two terms and 20percent sign? no results? (4 posts)

  1. sepp88
    Posted 3 years ago #

    This is my searchform.php template:

    <form class="search-form" action="<?php echo home_url( '/suche/' ); ?>" method="get">
            <div class="input-inside-label">
                <label for="s">Suche…</label>
                <input type="text" name="s" class="s" value="<?php the_search_query(); ?>" />
            <button type="submit" class="search-button">Suchen</button>

    Since I'm developing a page in german language I want the german word "suche" instead of "search".

    When searching for car in the searchbar I get all results for car just as you'd expect it.

    If I search however for beautiful car the search-page doesn't return anything because the search-string is transformed to beautiful20%car.

    Any idea what could cause this behaviour and how to fix this?

    In my search.php template I have this <h3><?php echo get_search_query(); ?></h3> which also shows that the search query was beautiful20%car and not beautiful car. Why is that?


    Maybe it's because of the following functions inside functions.php

     * Change search- & paginationbase
    add_action( 'generate_rewrite_rules', 'wr_generate_rewrite_rules' );
    function wr_generate_rewrite_rules( $rewrite ) {
        $rewrite->rules = array_merge( array(
             'suche/([^/]+)(?:/seite/(\d+))?/?' => 'index.php?s='.$rewrite->preg_index(1).'&paged='.$rewrite->preg_index(2)
        ), $rewrite->rules );
    add_filter( 'get_pagenum_link', 'wr_search_pagenum_link' );
    function wr_search_pagenum_link( $link ) {
        if ( !is_search() )
            return $link;
        // Attempt to parse the page number from the provided URL
        if ( !preg_match( '#/page/(\d+)#', $link, $matches ) )
            return $link;
        // Return a re-formed URL
        return home_url( '/suche/' . urlencode( get_query_var( 's' ) ) . '/seite/' . $matches[0] );

    However I got help with those functions and don't actually know how they work.

  2. Andrew
    Bawk bawk moderator
    Posted 3 years ago #

    20% represents a space.
    The search results may struggle to find multiple word searches. This is more ambiguous.

  3. sepp88
    Posted 3 years ago #

    I know that %20 represents a space. However in previous wordpress installations and sites I worked with two words always worked in my search box.

    There would be results for beautiful car not just for beautiful OR car.

    In previous installations the search worked like this for two words …


    However this time I want to rewrite /?s= to suche but have also two words work in the search.

    Any ideas?

  4. sepp88
    Posted 3 years ago #


    I found this in my script.js

    $('.search-form').submit(function(e) {
            location.href = $(this).attr('action') + escape( $(this).find('.s').val() );

    When uncommenting it my search doesn't work at all. Always throws a 404 since my url does look like this suche/?s=wordxyz

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.