How to show related posts with Content Views Pro?

Since version 4.4.0, you can show related posts of any post easily, by adding the View shortcode with additional parameter to the post’s content editor.

1. Shortcodes To Show Related Posts

  • Show related posts in same category as the current post

    [pt_view id="VIEW_ID" cat="GET_CURRENT"]
    
  • Show related posts in same tag as the current post

    [pt_view id="VIEW_ID" tag="GET_CURRENT"]
    
  • Show related posts in same custom taxonomy “Testimonial” as the current post

    [pt_view id="VIEW_ID" taxonomy="testimonial" terms="GET_CURRENT"]
    

    You can replace “testimonial” by any custom taxonomy in your WordPress site.

  • Detect taxonomy of current post automatically to show related posts

    [pt_view id="VIEW_ID" taxonomy="GET_CURRENT" terms="GET_CURRENT"]
    
  • Limit the number of related posts to show

    [pt_view id="VIEW_ID" cat="GET_CURRENT" limit=4]
    

2. How to show related posts for each post automatically?

Please add this code to file functions.php in the theme’s folder:

// Content Views Pro - show related posts for each post
add_filter( 'the_content', 'cvp_theme_auto_show_related_posts', 999 );
function cvp_theme_auto_show_related_posts( $content ) {
	if ( is_single() ) {
		ob_start();
		echo '<h3>Related posts</h3>';
		echo do_shortcode( '[pt_view id="VIEW_ID" cat="GET_CURRENT"]' );
		$content .= ob_get_clean();
	}
	return $content;
}

3. How to show related posts for each Custom post (product, event, …) automatically?

Please add this code to file functions.php in the theme’s folder:

// Content Views Pro - show related posts for each custom post
add_filter( 'the_content', 'cvp_theme_auto_show_related_custom_posts', 999 );
function cvp_theme_auto_show_related_custom_posts( $content ) {
	if ( is_singular( 'CUSTOM_POST_HERE' ) ) {
		ob_start();
		echo '<h3>Related posts</h3>';
		echo do_shortcode( '[pt_view id="VIEW_ID" taxonomy="GET_CURRENT" terms="GET_CURRENT"]' );
		$content .= ob_get_clean();
	}
	return $content;
}

(replace CUSTOM_POST_HERE with the name of your custom post type)


Notice 1: please DO NOT replace GET_CURRENT with any value.

Notice 2: please replace VIEW_ID with ID of your View

Notice 3: it will show No posts found if there are no posts match the combination of shortcode parameters. In that case, please create new View for your purpose.

Notice 4: showing related posts by View doesn't support Ajax pagination. It supports Non-Ajax pagination only.