Home › Forums › Backend Issues (wp-admin) › How can I create an argument by 5 fields for faceted search?
Hi,
At first thanks for your suitable plugin. I got a problem. I have used ACF fields with 2 checkbox, 2 radio and 1 text. It’s working well. My problem is I need to create a faceted search with those 5 fields. I have followed a code of your forum. But I can’t create relation with this 5 fields. I need to 5 fields search together or individually. I have used if else but I think its not proper way. How can I create an argument by 5 fields for faceted search?
if(empty($bedroom OR $bathroom)){
$args = array(
‘numberposts’ => -1,
‘post_type’ => ‘apartment’,
‘meta_query’ => array(
‘relation’ => ‘AND’,
array(
‘key’ => ‘apartment_price’,
‘value’ => array($minp,$maxp),
‘compare’ => ‘BETWEEN’,
‘type’ => ‘NUMERIC’,
),
)
);
//var_dump($args);
}
elseif (!empty($bedroom OR $bathroom)) {
$args = array(
‘numberposts’ => -1,
‘post_type’ => ‘apartment’,
‘meta_query’ => array(
‘relation’ => ‘AND’,
array(
‘relation’ => ‘OR’,
array(
‘key’ => ‘bedroom’,
‘value’ => $bedroom,
‘compare’ => ‘=’
),
array(
‘key’ => ‘bathrooms’,
‘value’ => $bathroom,
)
),
array(
‘key’ => ‘apartment_price’,
‘value’ => array($minp,$maxp),
‘compare’ => ‘BETWEEN’,
‘type’ => ‘NUMERIC’,
),
)
);
}
if(isset($_GET[‘ap_features’])) {
$meta_query = array(‘relation’ => ‘OR’);
foreach ($_GET[‘ap_features’] as $value) {
$meta_query[] = array(
‘key’ => ‘apartment_features’,
‘value’ => ‘”‘.$value.'”‘,
‘compare’ => ‘LIKE’
);
}
$args = array(
‘numberposts’ => -1,
‘post_type’ => ‘apartment’,
‘meta_query’ => $meta_query
);
}else{
//echo ‘<h1>Not ap_features Selectetd</h1>’;
}
if(isset($_GET[‘community’])) {
$meta_query = array(‘relation’ => ‘OR’);
foreach ($_GET[‘community’] as $value) {
$meta_query[] = array(
‘key’ => ‘co_fetu’,
‘value’ => ‘”‘.$value.'”‘,
‘compare’ => ‘LIKE’
);
}
$args = array(
‘numberposts’ => -1,
‘post_type’ => ‘apartment’,
‘meta_query’ => $meta_query
);
}else{
//echo ‘<h1>Not community Selectetd</h1>’;
}
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
Are you building WordPress sites with ACF and @BeaverBuilder, and wanted to use your ACF Blocks in both the block editor and Beaver Builder?
— Advanced Custom Fields (@wp_acf) May 10, 2023
The BB team recently added support for using ACF Blocks in Beaver Builder. Check it out 👇https://t.co/UalEIa5aQi
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.