Wordpress高级搜索 - 记住所选的内容

时间:2017-11-23 11:38:59

标签: php wordpress

我正在创建一个Wordpress高级表单,在主页上,用户有3个字段可供选择,然后他们点击提交,然后进入另一个页面。

然而,当它到达该页面时,它会显示结果,但该页面上的相同字段不记得所选内容。

有没有办法实现这一点,所以它会记住并继续记住,直到他们离开那个页面?

我一直在研究它,但甚至不确定要搜索什么?...

修改

被要求添加我的代码以帮助解释它;

<form method="post" class="form_search" action="<?php bloginfo('url');?>/job-search/" >
<label>
    Job Title/Keywords
    <input type="text" name="s" class="search_job_title" placeholder="e.g. Truck Driver">
</label>
<label>
    Sector
    <select name="job-sector">
        <option disabled selected value> -- select an option -- </option>
        <?php 
            $terms = get_terms( 'job-sector' );
            if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){                                 
                foreach ( $terms as $term ) {
                    echo '<option>' . $term->name . '</option>';
                }                                   
            }
            ?>
    </select>
</label>
<label>
    Location
    <input type="text" name="job-location" class="search_job_location" placeholder="e.g. Manchester">
</label>
<label>
    <input type="submit" class="search_submit" value="Search">
    <!-- <input type="hidden" name="post_type" value="jobs-board"> -->
</label>
</form> 

1 个答案:

答案 0 :(得分:0)

您需要将POST变量添加到表单中:

<form method="post" class="form_search" action="<?php bloginfo('url');?>/job-search/" >
<label>
    Job Title/Keywords
    <input type="text" name="s" class="search_job_title" placeholder="e.g. Truck Driver" value="<?php echo isset($_POST["s"])?esc_attr($_POST["s"]):'';?>" >
</label>
<label>
    Sector
    <select name="job-sector">
        <option disabled selected value> -- select an option -- </option>
        <?php 
            $terms = get_terms( 'job-sector' );
            if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){                                 
                foreach ( $terms as $term ) {
                    echo '<option value="' . $term->name . '" 
                    '.(isset($_POST["job-sector"]) and urldecode($_POST["job-sector"])==$term->name)?'selected':''.'>' . $term->name . '</option>';
                }                                   
            }
            ?>
    </select>
</label>
<label>
    Location
    <input type="text" name="job-location" class="search_job_location" placeholder="e.g. Manchester" value="<?php echo isset($_POST["job-location"])?esc_attr($_POST["job-location"]):'';?>">
</label>
<label>
    <input type="submit" class="search_submit" value="Search">
    <!-- <input type="hidden" name="post_type" value="jobs-board"> -->
</label>
</form>