Home › Forums › Front-end Issues › How to get a URL from a Woo tag or category taxonomy field (ACF PRO)
Hi there,
I’m struggling with obtaining a URL from a selected product tag or category in an ACF taxonomy field. It doesn’t return anything.
I have designed a home page with repeater fields where my customer can make a box, and link to either a product, category, tag or a page. This is achieved by a button group and conditional logic.
I can’t obtain a URL from taxonomy objects (tried ID too). Could anyone point me in the right direction please?
<?php
if ( have_rows( 'home_sections' ) ) : ?>
<?php
while ( have_rows( 'home_sections' ) ) : the_row();
$catlink = get_sub_field( 'home_section_link_cat' );
$taglink = get_sub_field( 'home_section_link_tag' );
$linktype = get_sub_field( 'home_section_link_type' ); ?>
<?php if ($linktype == 'category') : ?>
<div class="pt-2 pb-2">
<?php if($catlink):
$term_name = get_cat_name( $term_id ) ;
$term_url = get_category_link( $term_id ); ?>
<a href="<?php echo $term_url; ?>" class="btn btn-primary"><?php echo $btn; ?></a>
<?php endif; ?>
</div>
<?php elseif ($linktype == 'tag') : ?>
<div class="pt-2 pb-2">
<?php if($taglink):
$term_name = get_cat_name( $term_id ) ;
$term_url = get_category_link( $term_id ); ?>
<a href="<?php echo $term_url; ?>" class="btn btn-primary"><?php echo $btn; ?></a>
<?php endif; ?>

What is the return format setting of these fields
$catlink = get_sub_field( 'home_section_link_cat' );
$taglink = get_sub_field( 'home_section_link_tag' );
$linktype = get_sub_field( 'home_section_link_type' );
You must be logged in to reply to this topic.
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.