Hi, not sure where to post this… I’m looking for some help with querying a taxonomy name based on a custom field value… Some info below:
$searchstring = '77-999-77';
My data roughly looks like this:
(taxonomy) product_cat - (name) Category 1 - (custom field) gc_number - (value I need to search) 77-999-77
(taxonomy) product_cat - (name) Category 2 - (custom field) gc_number - (value I need to search) 73-333-73
(taxonomy) product_cat - (name) Category 3 - (custom field) gc_number - (value I need to search) 76-666-76
I then need to display the product_cat
name to the user.
So for example, the $searchstring
above would return the result Category 1
.
Hopefully this makes some sense and any help would be greatly appreciated!
It depends on what version of ACF you’re using. 4 (from the WP repo) or 5 (Pro version)
In both cases you’re going to use get_terms()
https://developer.wordpress.org/reference/functions/get_terms/
In the most recent ACF 5 you can use use a meta query.
With ACF 4 you will need to get all the terms and loop through them to find the one with the right value, this is the same for any version of ACF < 5.5.0