Home Forums ACF PRO Pages by Category within Custom Field


Pages by Category within Custom Field

  • How do I display my custom fields that are only in a specific category? I have two custom fields (residential and commercial listings) and the client runs specials on the residential properties.

    I’d like to create a page separately from the residential listings that shows only the specials. I’ve dug through the documentation, but I either haven’t found what I need to do, or I just don’t understand it. Help?

    • apsolut

    • February 11, 2020 at 7:20 pm

    ACF documentation page: Addign fields to Taxonomy terms

    * this should go to archive.php or category.php
    * you can also target category like: category-name.php
    * Get things for ACF on category 
    $term_id        = null;
    $taxonomy       = null;
    $queried_object = get_queried_object();
    $queried_term = null;
    * Dont show on Search or 404 page
    if ( !$queried_object == null && !is_search() && !is_404() ) {
    	$taxonomy = $queried_object->taxonomy;
    	$term_id  = $queried_object->term_id;
    	$queried_term =  $taxonomy . '_' . $term_id;
    <?php if ( get_field( 'acf_true_false', $queried_term ) ) : ?>
        <?php if ( get_field( 'acf_text_field', $queried_term  ) ): ?>
                <?php the_field( 'acf_text_field', $queried_term  ); ?>
        <?php endif; ?>
    <?php endif; ?>

    Conditional tags, to show things only on one category:

    <?php if ( is_category('category_slug')  ): ?>
      <!-- show only on category_slug category, you can put ACF code here also -->
    <?php endif; ?>

    Hope it helps,

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

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.