Last active
August 29, 2015 14:02
-
-
Save carter2422/e63e3b4a2d1ef6eb5292 to your computer and use it in GitHub Desktop.
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
<?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