Support

Account

Home Forums ACF PRO displaying a custom field in category…

Solving

displaying a custom field in category…

  • Hi all.

    Thanks for any help in advance, have used ACF for loads of projects and thought I had it all figured out, but this one area has me stumped.

    I’ve created 2 custom fields that are links I’d like to display in the category.php template.

    I’ve got them to display in the posts categories page on the backend of the site by setting the “show this field group if” Taxonomy Term is equal to category, this shows the two custom fields no problem.

    The issue I have is how to show these fields on the front end of the site, I just cannot get my head around how to show terms.

    The custom fields I’ve created are called next_issue_link and previous_issue_link.

    Ideally I’d love to have an “if get field name” way of hiding the field if it’s empty.

    I’ve tried so many things I can’t remember them all, but nothing has worked.

    Any help would really be appreciated.
    Thanks
    Aaron

  • Sorry, as soon as I posted this I figured it out!

    This is the code I used…

    <?php
    $queried_object = get_queried_object();
    $taxonomy = $queried_object->taxonomy;
    $term_id = $queried_object->term_id;

    the_field(‘previous_issue_link’, $taxonomy . ‘_’ . $term_id);

    ?>

    Incase it helps anyone else in the future 🙂
    Thanks
    Aaron

  • Spoke too soon…

    Whilst I can now display the custom field in the categories page, I’m not sure how to implement the “if” statement.

    Thanks
    Aaron

  • Hi @aaronbennett

    I think you are on the right path. Maybe you can try this code:

    if(get_field('previous_issue_link', $taxonomy . '_' . $term_id)){
        the_field('previous_issue_link', $taxonomy . '_' . $term_id);
    }

    Hope this helps!

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.