Home › Forums › General Issues › List categories with extra fields › Reply To: List categories with extra fields
Alrightie then.. your code is extremely overdoing it!
You’ll want something like this:
<?php
$args = array( 'hide_empty' => '0');
$categories = get_categories($args);
if($categories){
echo '<ul>';
foreach($categories as $category) {
echo '<li>';
$image = get_field('nameofimagefield', 'category_'.$category->term_id);
echo '<img src="' . $image . ' />'; //change depending on the return value of the image field
echo '<span class="cat-title">' . $category->name . '</span>';
echo '<span class="cat-subtitle">' . get_field('nameofsubtitlefield', 'category_'.$category->term_id) . '</span>';
echo '<span class="cat-description">' . $category->description . '</span>';
echo '</li>';
}
echo '</ul>';
}
?>
dont forget to change the fieldnames
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've just released ACF 5.12.3 with a security fix to prevent arbitrary file uploads to forms with ACF fields.
— Advanced Custom Fields (@wp_acf) July 14, 2022
Now that we've released this update, we recommend updating your sites as soon as possible.
© 2022 Advanced Custom Fields.
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.