-
-
Save salcode/397467a9c282df992aef to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
/********************************************* | |
Contests CPT | |
**********************************************/ | |
/* Contest CPT :: Initiate CPT | |
**********************************************/ | |
function vs_register_contests_post_type() { | |
$labels = array( | |
'name' => 'Contests', | |
'singular_name' => 'Contest', | |
'add_new' => 'Add New', | |
'add_new_item' => 'Add New Contest', | |
'edit_item' => 'Edit Contest', | |
'new_item' => 'New Contest', | |
'view_item' => 'View Contest', | |
'search_items' => 'Search Contests', | |
'not_found' => 'No contests found', | |
'not_found_in_trash' => 'No contests found in trash.', | |
'parent_item_colon' => '', | |
'menu_name' => 'Contests' | |
); | |
$args = array( | |
'labels' => $labels, | |
'public' => true, | |
'publicly_queryable' => true, | |
'show_ui' => true, | |
'show_in_menu' => true, | |
'query_var' => true, | |
'rewrite' => true, | |
'capability_type' => 'post', | |
'has_archive' => true, | |
'hierarchical' => false, | |
'menu_icon' => 'dashicons-tickets', | |
'menu_position' => null, | |
'supports' => array('title','editor'), | |
'taxonomies' => array( 'contest-status' ), | |
); | |
register_post_type( 'contests', $args ); | |
} | |
add_action( 'init', 'vs_register_contests_post_type' ); | |
/* Contest CPT :: Add Taxonomy | |
**********************************************/ | |
function vs_register_contest_status_taxonomy() { | |
$labels = array( | |
'name' => 'Contest Status', | |
'singular_name' => 'Contest Status', | |
'search_items' => 'Search Contest Status', | |
'all_items' => 'All Contest Statuses', | |
'edit_item' => 'Edit Contest Status', | |
'update_item' => 'Update Contest Status', | |
'add_new_item' => 'Add New Contest Status', | |
'new_item_name' => 'New Contest Status Name', | |
'menu_name' => 'Contest Status' | |
); | |
register_taxonomy( 'contest-status', array('contests'), | |
array( | |
'hierarchical' => true, | |
'labels' => $labels, | |
'show_ui' => true, | |
'show_in_menu' => true, | |
'query_var' => true, | |
'rewrite' => array( 'slug' => 'contest-status' ), | |
) | |
); | |
} | |
add_action( 'init', 'vs_register_contest_status_taxonomy' ); | |
/* Add Archive Settings to Contests CPT | |
**********************************************/ | |
add_post_type_support( 'contests', 'genesis-cpt-archives-settings' ); | |
/* Call Contests List By Shortcode | |
**********************************************/ | |
function vs_register_contest_shortcode ( $atts ) { | |
$atts = (shortcode_atts(array( | |
'status' => 'current', | |
'orderby' => 'post_date', | |
), $atts ) ); | |
global $post; | |
$contest_atts = array( | |
'post_type' => 'contests', | |
'orderby' => $atts['orderby'], | |
'tax_query' => array( | |
array( | |
'taxonomy' => 'contest-status', | |
'field' => 'slug', | |
'terms' => $atts['status'], | |
) | |
)); | |
$contest_style = "contest-".$contest_atts['tax_query'][0]['terms']; | |
$output = "<ul class=\"".$contest_style."\">"; | |
$contests = new WP_Query( $contest_atts ); | |
if( $contests->have_posts() ) { | |
while( $contests->have_posts() ) { | |
$contests->the_post(); | |
$output .= "<li>".get_the_time('m/d/y')." :: <a href=\"'".get_permalink()."\" target=\"_blank\">".get_the_title()."</a></li>"; | |
} | |
} | |
else { | |
$output .= "<li>No contests found.</li>"; | |
} | |
$output .= '</ul>'; | |
return $output; | |
} | |
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