Forums

[resolved] How to keep search query in the search bar? (6 posts)

  1. TransPersonal
    Member
    Posted 2 years ago #

    Is there any way to keep the search terms in the search bar after the searcher has pressed "enter"? Like how in Google or YouTube the search terms still appear in the bar on the results page.

  2. Mark / t31os
    Moderator
    Posted 2 years ago #

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

  3. TransPersonal
    Member
    Posted 2 years ago #

    Thank you t31os_, that solution almost works. Currently I have:

    value="Search Posts, Tags and Categories"

    Although your code:

    value="<?php the_search_query(); ?>"

    keeps the search query in the search field it also gets rid of "Search Posts, Tags and Categories".

    I wanted that to be in the search field at first and only after the user enters the new search I wanted it to display the search query. Is that possible?

  4. Mark / t31os
    Moderator
    Posted 2 years ago #

    Inside the value...

    <?php if(is_search()) { the_search_query(); } else { ?>Search Posts, Tags and Categories<?php } ?>

    Does that help? :)

  5. TransPersonal
    Member
    Posted 2 years ago #

    It sure does, that you so much t310s_ your solutions have helped me a lot over the past few weeks!

  6. Mark / t31os
    Moderator
    Posted 2 years ago #

    You're welcome.... :)

Topic Closed

This topic has been closed to new replies.

About this Topic