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?