WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. sepp88
    Member
    Posted 1 year ago #

    This is my searchform.php template:

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

    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?

    Addition:

    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 Nevins
    Spam zapper & Volunteer Moderator
    Posted 1 year ago #

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

  3. sepp88
    Member
    Posted 1 year 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 …

    http://mydomain.com/?s=word1+word2

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

    Any ideas?

  4. sepp88
    Member
    Posted 1 year ago #

    Update:

    I found this in my script.js

    $('.search-form').submit(function(e) {
            e.preventDefault();
            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

Tags

No tags yet.