Skip to content

Instantly share code, notes, and snippets.

@salcode
Forked from dougdaulton/contests-by-shortcode.php
Last active March 8, 2016 21:25
Show Gist options
  • Save salcode/397467a9c282df992aef to your computer and use it in GitHub Desktop.
Save salcode/397467a9c282df992aef to your computer and use it in GitHub Desktop.
<?php
/* Call Contests List By Shortcode
**********************************************/
function vs_register_contest_shortcode ( $atts ) {
$output = '<ul>';
$contest_atts = shortcode_atts( array(
'post_type' => 'contests',
'tax_query' => array(
array(
'taxonomy' => 'contest-status',
'field' => 'slug',
'terms' => 'current'
)
)
), $atts );
$contests = new WP_Query( $contest_atts );
if( $contests->have_posts() ) {
while( $contests->have_posts() ) {
$contests->the_post();
echo "<li class=\"contest-".$contest_atts['terms']."\">".the_time('d/m/y')." :: <a href=\"'".get_permalink()."\" target=\"_blank\">".the_title()."</a></li>";
}
}
else {
echo 'No contests found.';
}
$output .= '</ul>';
}
add_shortcode( 'contests', 'vs_register_contest_shortcode' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment