Support

Account

Home Forums ACF PRO Pages by Category within Custom Field

Helping

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?

  • ACF documentation page: Addign fields to Taxonomy terms

    
    <?php 
    
    /**
    * 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  ) ): ?>
            <div>
                <?php the_field( 'acf_text_field', $queried_term  ); ?>
            </div>
        <?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)

The topic ‘Pages by Category within Custom Field’ is closed to new replies.