21 Feb 2017

Custom post types in a loop

The following creates a loop of custom post types. This example creates a testimomnials block. 


<?php $loop = new WP_Query( array( 'post_type' => 'testimonial',
'posts_per_page' => 4 )
); ?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>

<?php
$clientname = (types_render_field( "client-name", array( 'raw' => true) ));
$quote = (types_render_field( "quote", array( 'raw' => true) ));
?>

<p><?php echo $quote; ?>&nbsp;<span><?php echo $clientname; ?></span></p>

<?php endwhile; wp_reset_query(); ?>

Check this article for more information