• Hi,

    If nothing is typed, the Search Results page should not appear. Instead, the search icon should be disabled. How can I achieve this? If that’s not possible, how can I redirect to the Posts page if someone clicks the search icon without entering any text?

    • This topic was modified 2 months, 3 weeks ago by elsazehra.

    The page I need help with: [log in to see the link]

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author wpdreams

    (@wpdreams)

    Hi!

    The results page is always triggered automatically via WordPress core when the redirection happens, so the plugin can’t change that.

    I’m afraid the only way to do that is via some sort of a custom code – either via mod_rewrite or template redirect. I would suggest trying something like this:

    add_action( 'template_redirect', function() {
    if (
    isset( $_GET[ 's' ] ) &&
    trim($_GET[ 's' ]) === ''
    ) {
    wp_redirect( home_url( '/page/to/redirect/' ) );
    exit();
    }
    } );

    Please be very careful with custom codes, make sure to have a back-up and use the functions.php file in the theme directory or a snippets plugin to handle these codes.

    All the best,
    Ernest

    Thread Starter elsazehra

    (@elsazehra)

    I have to place this code only in functions.php file?

    Plugin Author wpdreams

    (@wpdreams)

    Yes – you can use that, but I rather recommend a code snippets plugin.

    Please be very careful, I could not test this code, so it may not work at all.

    All the best,
    Ernest

    Thread Starter elsazehra

    (@elsazehra)

    The code is working fine. How can I make the pages come first in the search result and then the Posts, and Custom Posttypes?

    Thanks for the help!

    Plugin Author wpdreams

    (@wpdreams)

    Great!

    I’m afraid that type of ordering is not possible within the Lite version.

    All the best,
    Ernest

    Thread Starter elsazehra

    (@elsazehra)

    Is it possible to achieve this using custom code? This is important because it’s a client requirement.

    Plugin Author wpdreams

    (@wpdreams)

    Could be doable, but it’s much more complicated. I’m afraid I don’t have a custom code or a modification for that.

    All the best,
    Ernest

    Thread Starter elsazehra

    (@elsazehra)

    Can you please provide me modified the code? It will be very helpful.

    Plugin Author wpdreams

    (@wpdreams)

    I’m very sorry, but I don’t have a code for this. If I had I would have shared already ??

    All the best,
    Ernest

Viewing 9 replies - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.