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,
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.