Home Forums Front-end Issues Retrieve images on front-end (for a custom taxonomy)


Retrieve images on front-end (for a custom taxonomy)

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

        $custom_terms = get_terms('project_category');
        foreach($custom_terms as $custom_term) {
            $args = array('post_type' => 'project',
                          'posts_per_page' => -1,
                'tax_query' => 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();

    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.

Viewing 1 post (of 1 total)

The topic ‘Retrieve images on front-end (for a custom taxonomy)’ is closed to new replies.