Created
February 28, 2020 12:04
-
-
Save dexit/de529f4e41748e0e8cd8b737e33f01be to your computer and use it in GitHub Desktop.
Recent Custom Post Type SHortcode
This file contains hidden or 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 | |
// recent posts shortcode | |
// @ | |
function dexit_project_list($atts, $content = null) { | |
global $post; | |
extract(shortcode_atts(array( | |
'post_type' => 'project', | |
'post_status' => 'publish', | |
'cat' => '', | |
'num' => '10', | |
'order' => 'DESC', | |
'orderby' => 'post_date', | |
), $atts)); | |
$args = array( | |
'post_type' => $post_type, | |
'post_status' => $status, | |
'cat' => $cat, | |
'posts_per_page' => $num, | |
'order' => $order, | |
'orderby' => $orderby, | |
); | |
$output = ''; | |
$posts = get_posts($args); | |
foreach($posts as $post) { | |
setup_postdata($post); | |
$output .= '<li><a href="'. get_the_permalink() .'">'. get_the_title() .'</a></li>'; | |
} | |
wp_reset_postdata(); | |
return '<ul>'. $output .'</ul>'; | |
} | |
add_shortcode('recent_posts', 'dexit_project_list'); | |
// usage [recent_posts] | |
// usage [recent_posts post_type="PROJECT/PAGE/POST" post_status="STATUS" cat="CAT ID" posts_per_page="QTY" order="ASC/DESC" orderby=""] | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment