Home › Forums › ACF PRO › Get_Field Not Showing in Category Array › Reply To: Get_Field Not Showing in Category Array
Okay I figured it out. I trimmed off the subcategories, but my problem was that I was not associating category with the field and value. So the $cat was acting as the post id in the same way that a page will render an ACF value.
<?php
$taxonomy = 'product_cat';
$orderby = 'name';
$show_count = 0; // 1 for yes, 0 for no
$pad_counts = 0; // 1 for yes, 0 for no
$hierarchical = 1; // 1 for yes, 0 for no
$title = '';
$empty = 0;
$post_id = 1;
$args = array(
'taxonomy' => $taxonomy,
'orderby' => $orderby,
'show_count' => $show_count,
'pad_counts' => $pad_counts,
'hierarchical' => $hierarchical,
'title_li' => $title,
'hide_empty' => $empty,
);
$all_categories = get_categories( $args );
foreach ($all_categories as $cat) {
if($cat->category_parent == 0) {
$category_id = $cat->term_id;
$icon = get_field('category_icon', $cat);
echo '<div class="cat-box"><a href="'. get_term_link($cat->slug, 'product_cat') .'">'. $cat->name;
echo '<div class="clear"></div>'. $icon;
echo '</a></div>';
}
}
?>
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.