Display all the terms within a custom taxonomy

Question

I am looking to make a few different displays on the home page of terms within certain taxonomies as well as their image field as defined by ACF.

I have been looking online and found 2 main different ways to do this and would like to initially ask what is the difference between the two:?

WP_Term_Query();

and

get_terms();

This is the code I have so far but it does not seem to work with the_title() and the_permalink().

Also, it displays the ACF image field of the first result but then repeats the same image for the others.
The ACF custom image field on the term is ‘artist_thumbnail_image’

<?php
$args = array(
    'taxonomy'               => 'artist',
    'orderby'                => 'name',
    'order'                  => 'ASC',
    'hide_empty'             => false,
    'meta_key'               => 'artist_featured',
    'meta_value'             => '1',
    'meta_compare'           => '==',
);
$the_query = new WP_Term_Query($args);
foreach ($the_query->get_terms() as $term) { ?>
    <?php echo $term->name; ?>

    <?php
    $featuredartistid = $term->term_id;
    $featuredartist = get_field('artist', $featuredartistid);
    $featuredartistthumbnailimage = get_field('artist_thumbnail_image', $featuredartist);
    $featuredartistthumbnailimagesize = 'thumbnail'; ?>

    <a href="<?php echo the_permalink(); ?>">
        <?php echo wp_get_attachment_image($artistthumbnailimage, $artistthumbnailimagesize); ?>
    </a>

<?php } ?>
0
iamonstage 7 months 0 Answers 100 views 0

Leave an answer