Created
February 28, 2014 21:22
-
-
Save petenelson/9280180 to your computer and use it in GitHub Desktop.
WordPress: Advanced Custom Fields, find taxonomy term by custom value
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function get_term_by_value($taxonomy, $field, $value) { | |
// probably a better way to do this, but this works for now | |
// get_field is part of Advanced Custom Fields | |
if (function_exists('get_field')) { | |
foreach (get_terms( $taxonomy ) as $term) { | |
$field = get_field($field, $term); | |
if ($value == $field) | |
return $field; | |
} | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment