Home › Forums › General Issues › Page link to taxonomy / category page › Reply To: Page link to taxonomy / category page
Hi All,
This can be done as follows:
Field Type: Taxonomy
Taxonomy: Select your category
Appearance: Select
Return Value: Term Object (not Term ID)
Here’s how to display it on your Theme:
<?php $cat_link_term = get_field( 'my_category_url' ); ?>
<?php if ( $cat_link_term ): ?>
<a href="<?php bloginfo('url'); ?>/<?php echo $cat_link_term->slug; ?>"><?php echo $cat_link_term->name; ?></a>
<?php endif; ?>
Here’s how to us it within a repeater:
<?php while(the_repeater_field('my_category_repeater')) { ?>
<?php $cat_link_term = get_sub_field( 'my_category_url' ); ?>
<?php if ( $cat_link_term ): ?>
<a href="<?php bloginfo('url'); ?>/<?php echo $cat_link_term->slug; ?>"><?php echo $cat_link_term->name; ?></a>
<?php endif; ?>
<?php } ?>
Thanks,
Lee.
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.