For anyone who needs it, my error was that I had to use
get_term_link(term-slug, taxonomy-slug)
with the term slug and the taxonomy slug, while I was using the ID and did not use the taxonomy slug.
So the final code I used is:
$terms = get_field('acf_tax_fieldname');
if( $terms ) {
foreach( $terms as $term ) {
$term_name = get_term( $term )->name;
$term_slug = get_term( $term )->slug;
$term_link = get_term_link( $term_slug , 'wp_tax_slug' );
echo "<a href='" . $term_link . "'>" . $term_name . "</a>";
}
}
Update:
if I try to echo only my term name it appers completely empty,
if I try to echo only my term link, the warning “ltrim() expects parameter 1 to be string” appears
@hube2 thank you very much!
@hube2 thank you!
I have a similar case: I have a set of nine mandatory fields in comments, and I need to hide all of them to users who have already posted a comment. So, the following comments from the same users would be only basic text with no custom fields.
Can I put an array in the first line of code, or the set name, or what?
Thanks in advance
Thanks, it worked like a charm!
Just a note about deleting fields, in case someone needs it:
to delete a field inside a group i used this formula
groupname_fieldname
it works even if groups names and fields names already contain underscores, i.e.:
Group name: my_group
Field name: my_field
delete_field('my_group_my_field', $post_id);
Also, how can I reset/clear the values of previous fields that I used to write the name and other metadata after I save the post?
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.