Forum Replies Created
Viewing 1 post (of 1 total)
-
AuthorPosts
-
nickjcoMember
First we need to modify the search form and add the hidden input field:
<input type="hidden" name="post_type" value="product">
This will tell search that we are searching for a specific post type. Here is the function I created with the hidden input field.
function custom_products_search( $form, $search_text, $button_text, $label ) { $form = sprintf( '<form method="get" class="search-form" action="%s" role="search">%s<input type="search" name="s" placeholder="%s" /><input type="submit" value="%s" /><input type="hidden" name="post_type" value="product"></form>', home_url( '/' ), $label, $search_text, esc_attr( $button_text ) ); return $form; }
and then I modified your function above to with the add_filter and remove_filter lines:
function genesis_search_primary_nav_menu( $menu, stdClass $args ){ if ( 'primary' != $args->theme_location ) return $menu; if( genesis_get_option( 'nav_extras' ) ) return $menu; add_filter( 'genesis_search_form', 'custom_products_search', 10, 4 ); $menu .= sprintf( '<li class="custom-search">%s</li>', __( genesis_search_form( $echo ) ) ); remove_filter( 'genesis_search_form', 'custom_products_search', 10 ); return $menu; }
I added the filter in this function so that it will only affect that form you are adding. Hope this helps!
-
AuthorPosts
Viewing 1 post (of 1 total)