Support

Account

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>';
    }