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' );