简体   繁体   中英

Control Search Parameters in PHP Wordpress

Search parameters are null in PHP Wordpress

When user press search button, it make query string parameters even if search fields are empty

www.example.com/?ssc=&sst=&s=

How i can check it and remove (Don't Allow) null parameters from url

If you know where your form is situated, add required to input text

<input type="text" name="s" id="search" value="<?php the_search_query(); ?>" required />

or else create searchform.php in your theme directory and add following code

<form action="/" method="get">
    <label for="search">Search in <?php echo home_url( '/' ); ?></label>
    <input type="text" name="s" id="search" value="<?php the_search_query(); ?>" required  />
    <input type="image" alt="Search" src="<?php bloginfo( 'template_url' ); ?>/images/search.png" />
</form>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM