Hi everybody.
I am using this snippet to display terms:
<p><strong>Label</strong> <?php the_terms($post->ID, 'variable'); ?></p>
The output give me a term surrounded by a link, as WordPress do.
How can I have the terms without link?
Thanks for your help.
Marco
Hi There,
Thanks for reaching out to us.
Are you using an ACF taxonomy field? if that’s the case, then you can easily use the get_field function to return the taxonomy and display it without a link.
Alternatively, you can also make use of the WP get_terms function which returns the term as opposed to displaying it on the screen.
https://developer.wordpress.org/reference/functions/get_terms/
Hope this helps.
Hi James.
I tried following code:
<p>
<?php $variable = get_field('variable', false, false); ?>
<strong>Term</strong> <?php echo $variable; ?> </p>
but I have no results
If I try
<p>
<strong>Variable</strong> <?php the_terms($post->ID, 'variable' ); ?> </p>
it works, but the term is displayed with a link
Any suggest?
Solved in this way:
<?php $term_list = wp_get_post_terms($post->ID, 'term_name', array("fields" => "all")); ?>
<strong>Term name</strong> <?php echo $term_list[0]->name ; ?>
If you want to display a term in a if statement:
<?php if( get_terms('term_name') ): ?>
<?php $term_list = wp_get_post_terms($post->ID, 'term_name', array("fields" => "all")); ?>
<p><strong>Term name</strong> <?php echo $term_list[0]->name ; ?></p>
<?php endif; ?>