如果没有选择,当用户单击提交按钮时如何保持当前URL

时间:2019-12-01 17:07:40

标签: wordpress search search-form

我使用自定义帖子类型构建搜索表单,我尝试将自定义字段添加到我的搜索表单中并获得成功,但是现在我想在用户单击提交按钮而不选择时保留主目录/当前URL,该怎么做? 我在searchform.php中使用了这些代码

    <div class="row">
        <div class="col large-4" style="display: none;">
            <input type="search" class="search-field mb-0" name="s" value="<?php echo esc_attr( get_search_query() ); ?>" id="s" placeholder="Search" />
        </div>
        <div class="col large-3">
            <select name = "custom-field-1" id="custom-field-1">
                <option value ="">Custom field 1</option>
                <?php 
                $args = array(
                    'hide_empty' => '0',
                    'taxonomy' => 'custom-field-1'
                );
                $list = get_categories($args);
                ?>
                <?php foreach($list as $cate):?>
                    <option value = "<?php echo $cate->slug;?>"><?php echo $cate->name;?></option>
                <?php endforeach;?>
            </select>
        </div>
        <div class="col large-3">
            <select name = "custom-field-2" id="custom-field-2">
                <option value ="">Custom field 2</option>
                <?php 
                $args = array(
                    'hide_empty' => '0',
                    'taxonomy' => 'custom-field-2'
                );
                $list = get_categories($args);
                ?>
                <?php foreach($list as $cate):?>
                    <option value = "<?php echo $cate->slug;?>"><?php echo $cate->name;?></option>
                <?php endforeach;?>
            </select>
        </div>
        <div class="col large-3">
            <select name = "custom-field-3" id="custom-field-3">
                <option value ="">Custom field 3</option>
                <?php 
                $args = array(
                    'hide_empty' => '0',
                    'taxonomy' => 'custom-field-3'
                );
                $list = get_categories($args);
                ?>
                <?php foreach($list as $cate):?>
                    <option value = "<?php echo $cate->slug;?>"><?php echo $cate->name;?></option>
                <?php endforeach;?>
            </select>
        </div>
        <div class="col large-3">
            <button type="submit">
                Search now
            </button>
        </div>
    </div>
</form>

0 个答案:

没有答案