Support

Account

Home Forums ACF PRO Get link from taxonomy field

Solved

Get link from taxonomy field

  • Hi,

    Trying to grab a link that is added in the category taxonomy and add it to a category within a list of categories.

    <?php
    $queried_object = get_queried_object();
    $taxonomy = $queried_object->taxonomy;
    $term_id = $queried_object->term_id;
    $category_link = get_field('category_link', $category_link . '_' . $term_id);
    ?>
    <div class="product-list-wrap">
    	<div class="container container-product-list">
    		<div class="inner-content-wrapper">
    			<?php
    			$categories = get_categories();
    			echo '<ul class="product-categories">';
    			echo '<li class="all-cat"><a href="">All</a></li>';
    			foreach($categories as $category) {
    			   echo '<li><a href="' . $category_link . '">' . $category->name . '</a></li>';
    			}
    			echo '</ul>';
    			?>
    		</div>
    	</div>
    </div>

    https://imgur.com/a/MGhvW

  • Found my solution here:

    <?php
    			$args = array( 'hide_empty' => '0');
    			$categories = get_categories($args);
    			if($categories){
    				echo '<ul class="product-categories">';
    				foreach($categories as $category) {
    					echo '<li>';
    					$link = get_field('category_link', 'category_'.$category->term_id);
    					
    					echo '<a href="'.$link.'"><span class="cat-title">' . $category->name . '</span></a>';
    					
    					echo '</li>';
    				} 
    				echo '</ul>';
    			}    
    
    			?>
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Get link from taxonomy field’ is closed to new replies.