Site logo

Archived topic

Change the search field requests to the database from GET to POST

3 replies · Started by Domenico on January 26, 2023

Viewing posts 1–4 of 4

Hello.
I would like to change the method in which requests to the database are handled when doing a search from the search field. Generatepress manages requests using the GET method and every time a search is performed a page is generated with this url: nomesito.it/?s=term-searched
Also you create a page with searched term h1

This for me is a problem because it is exposed to attacks by negative seo.

Can you help me change the method of handling database requests from the lookup field from GET to POST?
Furthermore, I would like the page with the result to always have the same url: sitename/page-result.

I would like to be able to insert a php code via WP Codebox which I have already installed as a plugin.
Or with Advanced Script or whatever.

Thanks a lot for your help.

Hi Domenico,

Try this PHP filter for GP's navigation search:

add_filter('generate_navigation_search_output', function() {
			printf(
				'<form method="post" class="search-form navigation-search" action="%1$s">
					<input type="search" class="search-field" value="%2$s" name="s" title="%3$s" />
				</form>',
				esc_url( home_url( '/' ) ),
				esc_attr( get_search_query() ),
				esc_attr_x( 'Search', 'label', 'generatepress' )
			);
});

Works great!
Thank you so much Ying!

No Problem, glad to help :)

This archived topic is closed to new replies.