Skip to content

Instantly share code, notes, and snippets.

@vienhoang
Created August 11, 2014 16:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vienhoang/d92a4d34648eb614a71a to your computer and use it in GitHub Desktop.
Save vienhoang/d92a4d34648eb614a71a to your computer and use it in GitHub Desktop.
WordPress: Custom post type shortcode
<?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