Home › Forums › Front-end Issues › Taxonomy terms not showing up in select field (get_field_object) › Reply To: Taxonomy terms not showing up in select field (get_field_object)
The taxonomy field does not have an array of ‘choices’, like the select field does, because the choices are loaded from the database, they are not typed out in the ACF configuration.
You should use a database query for this:
global $wpdb;
$customTaxonomy = 'category';
$sql = "
SELECT
te.term_id,
te.name
FROM $wpdb->terms te
LEFT JOIN $wpdb->term_taxonomy tt
ON tt.term_id = te.term_id
WHERE tt.taxonomy = '$customTaxonomy'
";
$taxonomies = $wpdb->get_results( $sql, ARRAY_A );
if ( $taxonomies ) {
echo '<select name="somename">';
foreach( $taxonomies as $item ) {
echo '<option value="' . $item['term_id'] . '">' . esc_html( $item['name'] ) . '</option>';
}
echo '</select>';
}
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’re reaching out to our multilingual users to ask for help in translating ACF 6.1. Help make sure the latest features are available in your language here: https://t.co/TkEc2Exd6U
— Advanced Custom Fields (@wp_acf) May 22, 2023
© 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.