Support

Account

Home Forums ACF PRO Pages by Category within Custom Field Reply To: Pages by Category within Custom Field

  • 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,