Thanks for the reply! that works great, however, im unable to print the custom taxonomy name, how can I achieve this in my template?
right now I have this: <?php the_field('manufacturer'); ?> and it will print the cat id
I now put this on one line in order to echo a part of an url: <?php $term = get_field('manufacturer'); if( $term ): ?><?php echo $term->name; ?><?php endif; ?>
Is there any way to shorten the code any further? I just need the taxonomy name.
for example, would it be a problem to pull the “if” statement out?
If you make the field Required, then you can do away with the if statement completely <?php $manufacturer = get_field('manufacturer'); echo $manufacturer->name; ?>. Otherwise you can shorten the notation a bit like this: <?php $manufacturer = get_field('manufacturer'); if( $manufacturer ) echo $manufacturer->name; ?>. If you’re doing more than just echoing the name within the statement then stick in curly braces.
That being said, when I tested this just now it always returned an array of objects (as taxonomies are inherently multi-selectable even if you only actually give the option to select them using radio buttons) necessitating a foreach loop, but if your example code worked for you then clearly I’m setting my test up differently from you.
Viewing 7 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users