Home › Forums › Front-end Issues › Reverse Query ACF Term "meta" › Reply To: Reverse Query ACF Term "meta"
ACF save the taxonomies’ value in the wp_options
table. In this case, you need to use the wpdb class.
Here’s an example how to do it:
// you can set the ID automatically. This is just an example
$location_id = 99;
// this is the taxonomy b's slug
$taxonomy_slug = 'taxonomy_b';
// this is the taxonomy b's parent field name
$taxonomy_field_name = 'location_field_name';
$rows = $wpdb->get_results($wpdb->prepare(
"
SELECT option_name
FROM {$wpdb->prefix}options
WHERE option_name LIKE %s
AND option_value = %s
",
$taxonomy_slug . '_%_' . $taxonomy_field_name,
$location_id
));
$unit_ids = array();
foreach( $rows as $row ){
preg_match('/^' . $taxonomy_slug . '_(\d*)_' . $taxonomy_field_name . '$/', $row->option_name, $matches);
$unit_ids[] = $matches[1];
}
$terms = get_terms(array(
'taxonomy' => $taxonomy_slug,
'hide_empty' => false,
'include' => $unit_ids,
));
print_r($terms);
I hope this helps 🙂
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.