Skip to content

Instantly share code, notes, and snippets.

@uandidezign
Last active May 5, 2018 02:47
Show Gist options
  • Save uandidezign/136eee83cbfb1af781b9da03a0f99e8c to your computer and use it in GitHub Desktop.
Save uandidezign/136eee83cbfb1af781b9da03a0f99e8c to your computer and use it in GitHub Desktop.
This code snippet will create an CTP loop that can be inserted in any page via a short code.
<?php
function custom_short_code(){
ob_start();
$paged = ( get_query_var('paged') == 0 ) ? 1 : get_query_var('paged');
$call_cpt = new WP_Query(array(
'post_type' => 'custom_post_type',
'post_status' => 'publish',
'posts_per_page' => 8,
'order' => 'DESC',
'paged' => $paged
));
?>
<div class="et_pb_row">
<?php
if($call_cpt ->have_posts()) {
$i = 0;
while($call_cpt ->have_posts()): $call_cpt ->the_post();
?>
<div class="et_pb_column">
<div class="et_pb_text et_pb_module">
<div class="et_pb_text_inner">
<p>Custom Post Type Data</p>
</div>
</div>
</div>
<?php
$i++;
if($i % 2 == 0) echo '</div><div class="et_pb_row" >';
endwhile;
}
return ob_get_clean();
}
add_shortcode('name_of_shortcode', 'custom_short_code');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment