Site logo

Archived topic

WordPress Search (GP and WooCommerce)

3 replies · Started by Vijay on July 10, 2020

Viewing posts 1–4 of 4

Hi Tom,
I am creating a woocommerce site where I wish to be able to add a datalist of search terms. Any lightweight plugins that you would recommend? I want the visitor to be provided a suggestion of all words on the site (including product tags, categories). I am happy to build this list manually.

I have seen this support article, however, the code below is not working for me.

I need this to work in both the GP navigation search and default WordPress search box in footer. I am greatful for any help in this regards!

add_filter( 'generate_navigation_search_output', 'vj_wc_navigation_search' );
function vj_wc_navigation_search() {
	printf(
		'<form method="get" class="search-form navigation-search" action="%1$s">
			<input type="search" class="search-field" value="%2$s" name="s" title="%2$s" list="product-categories-list" placeholder="Search for a Great Shot!">
		</form>
		<datalist id="product-categories-list">
			<option>Architecture</option>
			<option>Big Ben</option>
			<option>Black & White</option>
			<option>Brooklyn Bridge</option>
			<option>Chrysler Building</option>  
			<option>Cloud</option>
			<option>Lake</option>
		</datalist>',
		esc_url( home_url( '/' ) ),
		esc_attr( get_search_query() ),
		esc_attr_x( 'Search...', 'label', 'generatepress' )
	);
}

PS: i am lovin GenerateBlocks

Hi there,

Is that function live on your website right now, or did you remove it?

It looks like it should do the trick.

Let me know :)

All good Tom. It works now.

Awesome :)

This archived topic is closed to new replies.