I am working on a child theme. I have a custom post type called ‘Projects’ & under this projects I have a custom taxonomy called ‘Categories’. This Categories contains all of my project category. Please take a look at the attached screenshot of the dashboard-project-categories:
I added a custom image field to this categories called ‘Category Icon’ & I uploaded images for every parent project categories.
Now I want to retrieve all of my project category names (excluding sub-categories) with their individual icons/images on front-page.php but I can’t figure it out how to achieve that.
Here is my code so far:
<?php
$custom_terms = get_terms('project_category');
foreach($custom_terms as $custom_term) {
wp_reset_query();
$args = array('post_type' => 'project',
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'project_category',
'field' => 'slug',
'terms' => $custom_term->slug,
),
),
);
$loop = new WP_Query($args);
if($loop->have_posts()) {
echo '<h2>'.$custom_term->name.'</h2>';
echo <strong>get_field('category_icon')</strong>;
while($loop->have_posts()) : $loop->the_post();
endwhile;
}
}
?>
But it gives me only the title which is ok but I am missing the icons/images. I look forward hearing from you.
If you need anymore information please just let me know.
Thanks a lot for your invaluable time.
Shihab.