can someone help me adapt the code?
I have an ACF with the field type “taxonomy”. I would love to spend this.
With the following code, however, all available taxonomies are displayed and not just the one in which the article is located?!?
<?php $zielgruppe = get_field( 'zielgruppe' ); ?>
<?php if ( $zielgruppe ) : ?>
<?php $get_terms_args = array(
'taxonomy' => 'zielgruppe',
'hide_empty' => 0,
'include' => $zielgruppe,
); ?>
<?php $terms = get_terms( $get_terms_args ); ?>
<?php if ( $terms ) : ?>
<?php foreach ( $terms as $term ) : ?>
<a href="<?php echo esc_url( get_term_link( $term ) ); ?>"><?php echo esc_html( $term->name ); ?></a>
<?php endforeach; ?>
<?php endif; ?>
<?php endif; ?>
https://ibb.co/PM98dsg
The aim is to create a button afterwards where the content is listed that has this taxonomy.
To you have your taxonomy field set to return Term Objects or Term ID? include
must be an array of Term IDs.
You can override the field setting and get just the IDs
<?php $zielgruppe = get_field( 'zielgruppe', false, false ); ?>
Your field may also be returning only a single value and you need an array
if ($zielgruppe) {
if (!is_array($zielgruppe)) {
$zielgruppe = array($zielgruppe);
}
....