Skip to content

Instantly share code, notes, and snippets.

@mattie02
Created October 10, 2014 16:41
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 mattie02/9f84743685dcca9b7295 to your computer and use it in GitHub Desktop.
Save mattie02/9f84743685dcca9b7295 to your computer and use it in GitHub Desktop.
CPT in Shortcode
function resultsLoop($content = null) {
global $wp_query;
$temp = $wp_query;
$wp_query= null;
$mypost = array(
'post_type' => 'result',
'orderby' => 'menu_order',
'posts_per_page' => '-1',
'order' => 'ASC'
);
$wp_query = new WP_Query( $mypost );
ob_start();
?>
<?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<?php
$url = wp_get_attachment_url( get_post_thumbnail_id() );
?>
<div class="col_3">
<div class="center">
<a href="<?php echo get_post_meta( get_the_ID(), 'wpcf-pdf', true ); ?>" target="_blank"><img src="<?php echo $url; ?>"></a>
</div>
<div class="center">
<p><?php the_title(); ?></p>
<p><?php echo get_post_meta( get_the_ID(), 'wpcf-client' , true ); ?></p>
</div>
</div>
<?php endwhile; ?>
<?php $wp_query = null; $wp_query = $temp;
$content = ob_get_contents();
ob_end_clean();
return $content;
}
add_shortcode("results-loop", "resultsLoop");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment