Created
August 11, 2014 16:22
-
-
Save vienhoang/d92a4d34648eb614a71a to your computer and use it in GitHub Desktop.
WordPress: Custom post type 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
<?php | |
add_shortcode( 'vh_movies', function() { | |
$loop = new WP_Query( | |
array( | |
'post_type' => 'vh_movie', | |
'orderby' => 'title' | |
) | |
); | |
if ( $loop->have_posts() ) { | |
$output = '<ul class="vh_movie_list">'; | |
while ( $loop->have_posts() ) { | |
$loop->the_post(); | |
$meta = get_post_meta(get_the_id(), ''); | |
// print_r($meta); | |
$output .= ' | |
<li> | |
<a href="' . get_permalink() . '">' | |
. get_the_title() . ' | '. | |
$meta['vh_movie_length'][0] . | |
'</a>' . | |
'<div>' . get_the_excerpt() . '</div>' | |
. '</li>'; | |
} | |
} else { | |
$output = 'No movies added.'; | |
} | |
return $output; | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment