Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Greg Winiarski

    (@gwin)

    Hi, do you have some security plugin installed maybe? They can cause such behavior.

    If you do not you can still try to disable the plugins you have installed one by one and see if and when the problem goes away.

    Thread Starter Ceyar

    (@ceyar)

    Hello, I don’t have plugin security and I tried to disable all other plugin( Imsanity and CFS ) But it’s the same issue. I’ve juste the wpadverts plugin and the Paypal standard plugin too.

    Thank you

    Plugin Author Greg Winiarski

    (@gwin)

    Hi, hmm you can add following code to your theme functions.php it will remove empty $_GET params from the search, so for example URL /adverts/?query=&location=London will become /adverts/?location=London.

    add_filter( "template_redirect", "cleanup_args", 20 );
    
    function cleanup_args() {
        if( ! is_page( adverts_config( 'config.ads_list_id' ) ) ) {
            return;
        }
    
        $args = array( 'query', 'location' );
        $redirect = false;
    
        foreach( $args as $arg ) {
            if( isset( $_GET[$arg] ) && empty( $_GET[$arg] ) ) {
                $redirect = remove_query_arg( $arg, $redirect );
            }
        }
    
        if( $redirect ) {
            wp_redirect( $redirect );
            exit;
        }
    }
    Thread Starter Ceyar

    (@ceyar)

    Works when booth argument are empty.

    When I just pass a location, it works too.

    But when I just pass a word in query like /adverts/?query=dog it return me post from article and not my ads even if they have the same words.

    When I pass my two arguments like:
    /adverts/?query=dog&location=paris
    It doesn’t work.

    Very strange…

    Maybe a conflict with the “query” argument passed in url? Is does just not work when we use query.

    Thank you.

    Thread Starter Ceyar

    (@ceyar)

    Hello Greg,

    Thank’s for tanking time. Your are right (Private message). I was getting this errors because I had a conflict code in my functions.php. This code was there to modify the search query to get just the post displayed and not the custom post type.

    So I found another solution adding a line of code in my custom search form:

    Just put the line of code in your custom search form:
    <input type="hidden" value="post" name="post_type" id="post_type" />

    WordPress Codex

    So, removing the conflict lines of code in my functions.php and pt a new condition to my searchform has resolved my problem.

    Thank you for your help.

    Best regards

    Dan

    Plugin Author Greg Winiarski

    (@gwin)

    Ok, great, thanks for feedback.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Empty search displaying all post from Main article’ is closed to new replies.