// There isn't any built-in function for related items but you can easily add your own section with some code like this
// IMPORTANT => change "book" to your post type name
// IMPORTANT => change myprefix to your custom prefix for styling purposes
// IMPORTANT => this will add related to the bottom of your post
// if you don't want it there you can change the order of your "blocks" array or you can instead
// hook the output into a different theme hook http://wpexplorer-themes.com/total/docs/action-hooks/
add_filter( 'wpex_book_single_blocks', function( $blocks ) {
$blocks['related'] = function() {
// Query posts
$related = new WP_Query( array(
'post_type' => 'book',
'posts_per_page' => 3,
'no_found_rows' => true,
'post__not_in' => array( get_the_ID() ),
) );
if ( $related->have_posts() ) : ?>
<div class="myprefix-related-posts wpex-row clr">
<?php
// Columns number
$columns = 3;
// Define counter variable
$count = 0;
// Your loop
while ( $related->have_posts() ) : $related->the_post();
// Add to counter
$count++; ?>
<div class="myprefix-related-entry col span_1_of_<?php echo $columns; ?> col-<?php echo $count; ?> clr">
<a href="<?php wpex_permalink(); ?>" title="<?php wpex_esc_title(); ?>">
<?php wpex_post_thumbnail( array(
'width' => 500,
'height' => 300,
) ); ?>
</a>
<h2><a href="<?php wpex_permalink(); ?>" title="<?php wpex_esc_title(); ?>"><?php the_title(); ?></a></h2>
<?php wpex_excerpt( array(
'length' => 20,
) ); ?>
</div>
<?php
// Reset counter
if ( $count == $columns ) {
$count = 0;
}
endwhile; ?>
</div>
<?php endif; wp_reset_postdata(); ?>
<?php };
return $blocks;
}, 40 );
Snippets: Related Items for Custom Post Type
All PHP snippets should be added via a child theme's functions.php file or via the Code Snippets Plugin (or alternative plugin)