Home › Forums › Front-end Issues › Filter post with a custom field in a taxonomy › Reply To: Filter post with a custom field in a taxonomy
After upgrading ACF to version 5, I managed to get it work with the following code but I am not sure whether this is the best approach.
$brands = get_terms(
'pwb-brand', array(
'hide_empty' => false,
'meta_query' => array(
array(
'key' => 'location',
'value' => '"paris"',
'compare' => 'LIKE'
)
)
));
if ($brands) {
foreach ($brands as $brand ) {
$brandslugs[] = $brand->slug;
}
}
$posts = get_posts(array(
'post_type' => 'product',
'numberposts' => -1,
'tax_query' => array(
array(
'taxonomy' => 'pwb-brand',
'field' => 'slug',
'terms' => $brandslugs
)
)
);
please let me know if there is a better way of doing it.
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!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.