<?php
// Get the current postID
$current_post = get_the_ID();
// Get the FIRST term ID from current article (only the first term, others are ignored)
// Change 'theme' to the slug of the taxonomy you want to use for the relationship
$first_term = get_the_terms( $current_post, 'theme' )[0];
// WP_Query arguments
$args = array(
'post_type' => array( 'article' ),
'posts_per_page' => 2, // how many related posts do you want?
'post__not_in' => array($current_post), // exlude the current post ID
'tax_query' => array(
array(
'taxonomy' => 'theme', // change 'theme' to your taxonomy slug
'terms' => $first_term,
'field' => 'term_id',
)
),
);
// The Query
$query = new WP_Query( $args );
// The Loop
if ( $query->have_posts() ) {
echo '<div class="similar_posts"><div>'; // Here you can see the markup for the wrappers
echo '<div class="grid-container">';
echo '<h2>Related Articles</h2>';
while ( $query->have_posts() ) {
$query->the_post();
// Here is your markup for your single item
// I have used a pods template below in this case (because trying to learn PODS)
// You could put your output here instead of a Pods template if you wanted
echo do_shortcode( '[pods template="Related posts from post term"]' );
}
echo '</div></div>';
echo '</div>';
}
// Restore original Post Data
wp_reset_postdata();