• Resolved bibliofille

    (@bibliofille)


    I have a custom page template, and I’d like to display all Custom Post Type posts under a specific taxonomy term. I’m trying to display the featured image, and the post title inside a link to the post.

    My CPT is People. The taxonomy is People Categories, and the Term slug is “njapf.”

    The query is working, however, I’m having the hardest time displaying the desired post items.

    I’m trying to display the featured image and post title, and have both the image and post title link to the post.

    Here is the full code for my query:

    <div class="artist-grid">
    
    	<?php 
    
    $args = array(
    'post_type' => 'people',
    'orderby'   => 'title',
    'order' => 'ASC',
    'tax_query' => array(
    array(
    'taxonomy' => 'people',
    'field' => 'slug',
    'terms' => 'njapf'
    )
    )
    );
    //$query = new WP_Query( $args ); // this line is useless in your code
     
    // The Query
    $the_query = new WP_Query( $args );
     
    // The Loop
    if ( $the_query->have_posts() ) {
    while ( $the_query->have_posts() ) {
    $the_query->the_post();
    
    echo '<div class="artist-grid-item">';
    
    if(has_post_thumbnail()){
    
    	echo '<a>'. get_permalink() . '</a>';
    
                   echo '<div class="artist-grid-image">' . get_the_post_thumbnail( $_post->ID, 'large' ) . '</div>';
                 }
    
    echo '<p>' . get_the_title() . '</p>';
    
    echo '</div>';
    
    }
    
    } else {
    // no posts found
    }
    /* Restore original Post Data */
    wp_reset_postdata();?>
    
    </div>

    What am I doing wrong?

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    I’m assuming you figured out your closing tag is misplaced, which is why this topic is marked as resolved. Sometimes people accidentally mark their topics as resolved when they are not. Topics with no replies add to such a suspicion. If the resolved status is not in error, please disregard.

    Thread Starter bibliofille

    (@bibliofille)

    Yep, of course I realized my syntax error shortly after posting the question. Thanks for checking in! This issue is, indeed, resolved.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Display CPT posts with Specific Taxonomy Term’ is closed to new replies.