paullacey78
12/14/2017 - 11:49 AM

Related posts lite

<div class="grid-50 tablet-grid-50">	
	<div class="fl-post-image">
		<a href="{@permalink}">{@post_thumbnail.large}</a>
	</div>
	<ul class="colorful_categories">
		[each theme]<li><a href="{@theme.permalink}" style="background:{@theme.color};">{@theme.name}</a></li>[/each]
	</ul>
	<h2 class="fl-post-feed-title"><a href="{@permalink}">{@post_title}</a></h2>
	<p>{@post_content, my_pods_excerpt}</p>
	<div class="fl-post-more-link">
		<a href="{@permalink}">Read</a>
	</div>
</div>
<?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();