Created
October 10, 2014 16:41
-
-
Save mattie02/9f84743685dcca9b7295 to your computer and use it in GitHub Desktop.
CPT in Shortcode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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