Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.