• Hello,

    When I research something with the WordPress search system, I’m redirected at the page search.php where the search results are displayed.
    I would like to not be redirected and have the results displayed in the current page.
    I use Avada theme (I know a theme limit a lot what we can do but I havn’t the choice…).

    Here is the code of the searchform :

    <form role="search" class="searchform" method="get" action="<?php echo esc_url_raw( home_url( '/' ) ); ?>">
    	<div class="search-table">
    		<div class="search-field">
    			<input type="text" value="" name="s" class="s" placeholder="<?php esc_html_e( 'Search ...', 'Avada' ); ?>" required aria-required="true" aria-label="<?php esc_html_e( 'Search ...', 'Avada' ); ?>"/>
    		</div>
    		<div class="search-button">
    			<input type="submit" class="searchsubmit" value="" />
    		</div>
    	</div>
    </form>

    I already try to change action="<?php echo esc_url_raw( home_url( '/' ) ); ?>" by action="<?php echo get_permalink(); ?> , but it only redirect me on the page 404.php.

    I think there is a loop somewhere I have to modify, but I don’t know in which file.

    Moreover I wan’t to use Relevanssi plug-in, and I’m affraid that too much modification in the code of the search system will cause a problem for the right functionning of the plug-in. Is that the case ?

    Thank you very much for the help you can provide me (and sorry for my approximate english),
    Morgane

Viewing 5 replies - 1 through 5 (of 5 total)
  • You can check with Relevassi plugin author whether there would be a problem or not or what kind of modifications won;t have an effect.

    I don;t know if it’d work or not but you may try this:

    https://wordpress.stackexchange.com/questions/50006/display-search-results-within-the-same-page

    Thanks,

    Saurabh

    Thread Starter axoloto

    (@axoloto)

    Hello @saurabhsaneja

    Thank you for your answer.

    Ok I will check on Relevanssi support if they can answer me on this point.

    I already try in many way the tips provided in your link, maybe I haven’t done it correctly, but it doesn’t work : the page doesn’t display anything or is loading endless.

    Moderator bcworkz

    (@bcworkz)

    Saurabh’s link outlines a good approach, but the devil is in the details. That approach could be independent of Relevanssi, or incorporate it. The specifics of how the form handling code does its search determines which way it goes. In either case, having the form submit to its own page and having the form handling code on the same page is a good approach.

    You could modify a theme template to accomplish this, but you might be better off with a custom page template. It depends on what else the page needs to do. We can help you here with general form coding, but in order to use Relevanssi’s features you would need to rely on the developer’s input, that is not something we generally address here. It does happen though that someone here has enough experience with a plugin that questions can be answered, but you cannot beat a plugin dev’s advice if you can get it.

    Thread Starter axoloto

    (@axoloto)

    Hello @bcworkz,
    Thank’s for your answer.

    I agree with what you said :
    – I have already create custom page template, ready to be coded !
    – I have already ask on the Relevanssi forum if they can tell me in general the impact of code modification on the plugin, I’m waiting for an answer. But yes, I will ask again after I begin to code, to show them about what is it more precisely.

    Have I to create a new form handling code by my-self ? Or can I find somewhere in my wordpress/theme files this code and just copy/past it in my template and change what need to be modify (lazy me haha) ?

    Thank’s for your advices

    Moderator bcworkz

    (@bcworkz)

    You can find form handling examples all over the Internet. It’s generic PHP, largely unrelated to WP. Where WP comes in is once you’ve handled the form, what to do with the data? Whatever you find, it will not be just copy/paste, it’ll need to be adapted to your situation. You are really coding your own, even if you take some hints and examples from elsewhere.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Display search results in the current page’ is closed to new replies.