Support » Fixing WordPress » Pass custom field value to get_category_link

  • I’m using the following code which echoes the custom sub field, which is the category ID (Advanced Custom Fields plugin)

    <?php echo the_sub_field('site_cat_link'); ?>

    I then want to use the following code to get the category link:

    <?php
    $category_id = get_sub_field('site_cat_link');
    $category_link = get_category_link( $category_id );
    ?>
    
    <a href="<?php echo esc_url( $category_link ); ?>" title="Category Name">Category Name</a>

    But that doesn’t seem to grab the category ID.

    Any ideas?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Do you want to get the category ID for a specific post or category loop page?

    Really I’m just trying to echo the contents of that site_cat_link field into get_category_link. That custom field contains the ID of the individual category.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Pass custom field value to get_category_link’ is closed to new replies.