Home › Forums › General Issues › Let users add to select field choices
Hi!
How can I make my members add choices to the select field themselves without them messing in my ACF field groups?
Is there a neat option for this or something?
Thanks!
The simplest way to approach this would be to associate the select field with a custom taxonomy, which users with appropriate privileges could add to.
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
You need to edit your field and change the return value from Term ID to Term Object, and then you can get the name from the object like this.
thanks!
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?
Thanks a lot!
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.
The topic ‘Let users add to select field choices’ is closed to new replies.
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 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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.