Skip to content

Instantly share code, notes, and snippets.

@ben-heath
Created April 11, 2018 15:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ben-heath/b5cdba0ea0886c628f5b25916598e173 to your computer and use it in GitHub Desktop.
Save ben-heath/b5cdba0ea0886c628f5b25916598e173 to your computer and use it in GitHub Desktop.
Shortcode list CPT posts
<?php
add_shortcode( 'video-testimonials', 'sls_video_testimonial_short_code' );
function sls_video_testimonial_short_code( $atts ) {
ob_start();
$query = new WP_Query( array(
'post_type' => 'video-testimonial',
'posts_per_page' => 4,
'order' => 'ASC',
'orderby' => 'title',
) );
if ( $query->have_posts() ) { ?>
<div class="vid-testimonials">
<?php while ( $query->have_posts() ) : $query->the_post(); ?>
<div class="indv_vid_test">
<h3>
<?php the_title(); ?>
</h3>
<p class="the_date">
<?php the_field("video_date"); ?>
</p>
<div class="the_video">
<?php echo wp_oembed_get(get_field("video_url"), array('width'=>295)); ?>
</div>
</div>
<?php endwhile;
wp_reset_postdata(); ?>
</div>
<div class="clearfix"></div>
<p id="more-vids"><a href="/video-testimonial/">View more</a></p>
<?php $myvariable = ob_get_clean();
return $myvariable;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment