如何解决根据自定义帖子类型的ACF字段搜索过滤器
我正在使用一种名为“ property”的自定义帖子类型,每个帖子内容中都有一些ACF字段(平方米,房间数,浴室数等)。 我该如何创建搜索表单以过滤示例“具有2个浴室或3个房间的所有属性”或“仅具有1个房间和1个浴室的所有属性”?
这是我尝试过的:
<form action="<?php home_url('/') ?>">
<input type="text" name="id" id="" placeholder="ID">
<select name="property_rooms" id="">
<option value="1">1 room</option>
...
</select>
<select name="property_bathrooms" id="">
<option value="1">1 bathroom</option>
...
</select>
...
<input type="hidden" name="post_type" value="property">
<input type="hidden" name="s" value="">
<button type="submit">filter</button>
</form>
我的自定义帖子类型是:
function cpt_property() {
register_post_type('property',array(
'labels' => array(
'name' => 'Propriedade','singular_name' => 'Propriedade','menu_name' => 'Propriedades','name_admin_bar' => 'Propriedades','add_new' => 'Adicionar nova propriedade','add_new_item' => 'Adicionar novo item','new_item' => 'Novo item','edit_item' => 'Editar item','view_item' => 'Ver item','all_items' => 'Todas as propriedades','search_items' => 'Buscar propriedades','featured_image' => 'Foto de capa','set_featured_image' => 'Definir como foto de capa','remove_featured_image' => 'Remover como foto de capa','use_featured_image' => 'Usar como foto de capa','archives' => 'Arquivos',),'public' => true,'has_archive' => true,'menu_position' => 2,'menu_icon' => 'dashicons-admin-multisite','supports' => array('title','author','thumbnail'),)
);
}
示例中的ACF字段:"property_rooms"
,"property_bathrooms"
,依此类推。我使用复选框作为字段类型。
<?php
$fields = get_field('property_rooms');
foreach($fields as $field) {
echo "<li>".$field."</li>";
}
?>
我应该使用自定义分类法而不是ACF?我没有在ACF文档中找到解决此问题的任何东西。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。