prokops
prokops

Reputation: 45

HTML GET Form: how to append to search term

I have this form:

        <form role="search" method="get" action="<?php echo esc_url( $destination ); ?>">
            <?php do_action( 'searchwp_live_search_widget_before_field' ); ?>
            <label>
                <input type="search" class="search-field" placeholder="<?php echo esc_attr( $placeholder ); ?>" value="" name="s" data-swplive="true" data-swpengine="<?php echo esc_attr( $engine ); ?>" data-swpconfig="<?php echo esc_attr( $config ); ?>" title="<?php echo esc_attr( $placeholder ); ?>" autocomplete="off">
            </label>
            <input type="hidden" name="post_type=product">
            <div class="flex-col top"> <button type="submit" value=""></button></div>
        </form>

As you see, I did insert an extra hidden input field to get "&post_type=product" into my result search string. The end result is however:

www.site.com/?s=TERM&post_type%3Dproduct=

The "=" sign is scrambled and there is an extra "=" at the end. How do I append "&post_type=product" to my form query without having to rewrite via js or similar?

Upvotes: 0

Views: 334

Answers (1)

Alberto
Alberto

Reputation: 12939

In the hidden input you have both name and value as every other input, and so the right way to use it is this:

<input type="hidden" name="post_type" value="product">

Upvotes: 1

Related Questions