我有这个表格:
<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>
如您所见,我确实插入了一个额外的隐藏输入字段,以将“&post_type = product”添加到结果搜索字符串中。但是最终结果是:
www.site.com/?s=TERM&post_type%3Dproduct =
“ =”符号被打乱,并且末尾还有一个额外的“ =”。如何在表单查询中附加“&post_type = product”,而不必通过js或类似方法重写?
在隐藏的输入中,您同时具有name
和value
作为其他输入,因此使用它的正确方法是:
<input type="hidden" name="post_type" value="product">