[Resolved] Search placeholder code overrides code restricting search to products

Home Forums Support [Resolved] Search placeholder code overrides code restricting search to products

Home Forums Support Search placeholder code overrides code restricting search to products

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1639732
    David Bennett

    I used the code from this documentation page to restrict search to products in WooCommerce.

    generate_navigation_search_output.

    Now I added the placeholder text code and while it shows the placeholder text OK, it overrides and stops the ‘restrict search to products in WooCommerce’ code from functioning.

    Help.

    Kind regards,

    David

    #1639801
    Leo
    Staff
    Customer Support

    Hi there,

    Try this code only:

    add_filter( 'generate_navigation_search_output', function() {
        printf(  
            '<form method="get" class="search-form navigation-search" action="%1$s">
                <input type="search" placeholder="Enter your search" class="search-field" value="%2$s" name="s" title="%3$s" />
                <input type="hidden" name="post_type" value="product" />
            </form>', 
            esc_url( home_url( '/' ) ), 
            esc_attr( get_search_query() ),   
            esc_attr_x( 'Search', 'label', 'generatepress' ) 
        ); 
    } );
    #1639895
    David Bennett

    That did it. Thanks. ๐Ÿ™‚

    #1639929
    Leo
    Staff
    Customer Support
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.