abs*_*tal 1 wordpress wordpress-theming wordpress-plugin
这是我的搜索表单的代码:
<form role="form">
<div class="form-group">
<select class="form-control custform">
<option>Make (Any)</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
</div>
<div class="form-group">
<select class="form-control custform">
<option>Model (Any)</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
</div>
<div class="form-group">
<select class="form-control custform">
<option>Min Price</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
</div>
<div class="form-group">
<select class="form-control custform">
<option>Max Price</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
</div>
<div class="form-group">
<div class="checkbox">
<label>
<input id="cars" type="checkbox"> Cars
</label>
</div>
</div>
<button type="submit" class="btn btn-primary btn-block btnsearch">
Find Vehicles <span class="glyphicon glyphicon-search"> </span> </button>
</form>
Run Code Online (Sandbox Code Playgroud)
以下是它的外观:
我添加了一些不在代码中的类别来显示它应该如何结束.
基本上我对如何在我从头编写的Wordpress主题中实现这一点毫无头绪.Make和Model都是自定义字段,Min Price和Max Price显然需要使用某种范围函数来返回价格范围内的结果.
品牌和型号下拉菜单需要仅显示已在自定义字段中输入的可用选项 - 如果这是有意义的.
任何帮助都非常受欢迎.
您可以创建自定义搜索表单.表单操作必须是您的特定搜索页面(新模板).
在新模板中,您可以使用此下面的查询:
$meta_query_args = array(
'relation' => 'AND', // "OR"
array(
'key' => '_my_custom_key',
'value' => 'Value I am looking for',
'compare' => '='
),
array(
'key' => '_your_min_model_key',
'value' => 1453,
'compare' => '>'
),
array(
'key' => '_your_max_model_key',
'value' => 1923,
'compare' => '<'
)
);
$meta_query = new WP_Meta_Query( $meta_query_args );
Run Code Online (Sandbox Code Playgroud)
并比较 param细节:
compare(string) - 要测试的运算符.可能的值为'=','!=','>','> =','<','<=','LIKE','NOT LIKE','IN','NOT IN','BETWEEN ','不在'之间','EXISTS'(仅在WP> = 3.5)和'NOT EXISTS'(也仅在WP> = 3.5).在WordPress 3.7中添加了值'REGEXP','NOT REGEXP'和'RLIKE'.默认值为'='.
// good coding
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3119 次 |
| 最近记录: |