Show results of custom code, api, another plugin

In case you used custom code to query posts, or used another plugin to get posts, you can use Content Views Pro to display these posts in a beautiful grid or list.
Here is the code you need to use:

$pids = array();

// #1: If there is existing variable contains array of post objects
// Replace $posts by the existing variable
if ( isset( $posts ) ) {
	foreach ( $posts as $post ) {
		$pids[] = $post->ID;
	}
} 
else {
	// #2: If there is existing loop
	// Replace null by the query variable
	$query_obj = null;
	while ( $query_obj ? $query_obj->have_posts() : have_posts() ) :
		$query_obj ? $query_obj->the_post() : the_post();
		$pids[] = get_the_ID();
	endwhile;
}

// Replace VIEW_ID with the ID string of your grid/list View
echo do_shortcode('[pt_view id="VIEW_ID" post_type="any" post_id="' . implode( ',', $pids ) . '"]');

Notice: Above code requires your knowledge of PHP.
Also, the view should NOT enable Live Filter or any kind of other filters, it should use default Filter Settings.

Best regards,

Scroll to Top