Support

Account

Home Forums General Issues get_category_link from taxonomy addon Reply To: get_category_link from taxonomy addon

  • Apologies for the confusion and thanks for helping out on this. I’ve removed the code that’s actually working from the example below and included the dump of what’s getting produced. It is getting the category ID from the ACF custom field.

    Custom fields in Use (to get category ID):
    site_cat_link = taxonomy field type (Taxonomy Add-on)
    cat_id = Text field type (I’ve just manually added the categories I want to pass, just to see if this works).

    Code:

    <?php if( get_field('site_cats') ): ?>
    	<?php while( has_sub_field('site_cats') ): ?>
    <?php
        $variable = get_sub_field('site_cat_link');
        var_dump($variable);
        $category_link = get_category_link( $variable );
        var_dump($category_link);
    ?>
    
    <p><?php echo the_sub_field('site_cat_link'); ?></p>
    <p><?php echo the_sub_field('cat_id'); ?></p>
    <a href="<?php echo esc_url( $category_link ); ?>" >Category</a>
    
    	<?php endwhile; ?>
    <?php endif; ?>
    

    Output when using cat_id (text field):
    Category string(3) “249” string(57) “http://www.mysite.com/inspiration-ideas/”
    249
    249
    Category string(3) “346” string(50) “http://www.mysite.com/tips-advice/”
    346
    346

    Output when using site_cat_link (taxonomy field):
    Category array(1) { [0]=> string(3) “249” } string(43) “http://www.mysite.com/news/”
    249
    249
    Category array(1) { [0]=> string(3) “346” } string(43) “http://www.mysite.com/news/”
    346
    346

    What I can’t understand is that even though both are outputting the correct category id’s. The taxonomy addon then doesn’t seem to be able to pass that to the link.