Display All Terms of Taxonomy in Page Template

Some Details:

  1. I have a custom post type with a slug called ‘residential.

  2. There’s a taxonomy associated with this custom post type with a slug of ‘residential_project_type’

  3. Inside this taxonomy there are several terms

  4. I’ve created a page template where I’ve created a tax_query

What I’m trying to accomplish:

I want to display all terms from this taxonomy on a page, outputting specific elements of the terms into an HTML layout such as…

  1. The term title
  2. The permalink to the term archive page
  3. And a custom image field attached to each term

I’ve built it out as makes sense to me but no luck getting the terms to display.

Thanks in advance for your help!

Here’s the code I have:

<?php
/*
* Residential Projects Types Archive Template
* Description: Template for Residential Project Types archive
*/

get_header(); ?>


<?php
    $the_query = new WP_Query( array(
        'post_type' => 'residential',
        'tax_query' => array(
            array (
                'taxonomy' => 'residential_project_types',
                'field'    => 'name',
            ),
        ),
    ) );
?>

<div id="main-content">
    <?php do_action( 'foundationpress_after_header' ); ?>

    <?php get_template_part( 'assets/partials/partial', 'mobilenav' ); ?>

    <?php get_template_part( 'assets/partials/partial', 'headings' ); ?>

    <?php do_action( 'foundationpress_before_content' ); ?>
    <?php if ( $the_query->have_posts() ) : ?>
        <?php /* Start the Loop */ ?>
        <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
            <a class="property-thumb-link"
               href="<?php the_permalink($post->ID); ?>">
                <div class="property-thumb column medium-6 small-12">

                    <img src="<?php the_field('category_image', $post->ID); ?>"
                         alt="<?php the_field ('category_image_alt', $post->ID); ?>" />

                    <div class="property-thumb-title">
                        <h2>
                            <?php the_title($post->ID); ?>
                        </h2>
                    </div>
                </div>
            </a>
        <?php endwhile; ?>
    <?php wp_reset_postdata(); ?>
    <?php endif; // End have_posts() check. ?>
    <?php do_action( 'foundationpress_after_content' ); ?>

</div>

<?php get_footer(); ?>

Read more here: Display All Terms of Taxonomy in Page Template

Leave a Reply

Your email address will not be published. Required fields are marked *