Skip to content

Instantly share code, notes, and snippets.

@carter2422
Last active August 29, 2015 14:02
Show Gist options
  • Save carter2422/e63e3b4a2d1ef6eb5292 to your computer and use it in GitHub Desktop.
Save carter2422/e63e3b4a2d1ef6eb5292 to your computer and use it in GitHub Desktop.
<?php
/*
Plugin Name: Show Posts Short Code
Version: 0.0.1
Author: Jonathan Williamson
*/
function jonathan_show_posts_shortcode($atts, $content = null ) {
extract( shortcode_atts(
array(
'post_type' => 'cgc_courses',
'tax' => 'category',
'terms' => ''
), $atts )
);
if($terms) {
if(strpos($terms, ',')) {
$terms = explode(',', $terms);
}
}
$display = '<ul>';
$post_args = array( 'post_type' => 'cgc_courses' );
$posts = get_posts($post_args);
if($posts) {
foreach ($posts as $p) {
$display .= '<li><a href="' . get_permalink($p->ID) . '">' . get_the_title($p->ID) . '</a></li>';
}
} else {
$display .= '<li>No posts found</li>';
}
$display .= '</ul>';
return $display;
}
add_shortcode('query_posts', 'jonathan_show_posts_shortcode');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment