Skip to content

Instantly share code, notes, and snippets.

@andyspicer
Created April 9, 2013 18:48
Show Gist options
  • Save andyspicer/5348298 to your computer and use it in GitHub Desktop.
Save andyspicer/5348298 to your computer and use it in GitHub Desktop.
WP - CPT List Shortcode
function rgp_listing_list_shortcode() {
$loop = new WP_Query(
array(
'post_type' => 'listing',
'orderby' => '_rgp_listing_status'
)
);
$output_active = '<ul class="rgp_active_list">';
$output_sold = '<ul class="rgp_sold_list">';
if ( $loop->have_posts() ) {
while( $loop->have_posts() ) {
$loop->the_post();
$meta = get_post_meta(get_the_id(), '');
$status = $meta['_rgp_listing_status'][0];
if ('2' == $meta['_rgp_listing_status'][0] )
{
$output_sold .= '
<li>
sold ' . get_the_title() . '
</li>';
}
else
{
$output_active .= '
<li>
active ' . get_the_title() . '
</li>';
}
}
$output = $output_active . $output_sold;
return $output;
}
else {
return 'There are no listings.';
}
}
add_shortcode('rgp_listings', 'rgp_listing_list_shortcode');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment