Forked from dougdaulton/contests-by-shortcode.php
Last active
March 8, 2016 21:25
Revisions
-
salcode revised this gist
Mar 8, 2016 . 1 changed file with 6 additions and 7 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -84,22 +84,21 @@ function vs_register_contest_status_taxonomy() { **********************************************/ 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'], ) )); -
dougdaulton revised this gist
Mar 8, 2016 . 2 changed files with 127 additions and 35 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,127 @@ <?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 ) { extract(shortcode_atts(array( 'status' => 'current', 'orderby' => 'post_date' ), $atts)); global $post; $contest_atts = array( 'post_type' => 'contests', 'orderby' => $orderby, 'tax_query' => array( array( 'taxonomy' => 'contest-status', 'field' => 'slug', 'terms' => $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' ); 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 charactersOriginal file line number Diff line number Diff line change @@ -1,35 +0,0 @@ -
dougdaulton renamed this gist
Mar 8, 2016 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ <?php /* Call Contests List By Shortcode **********************************************/ function vs_register_contest_shortcode ( $atts ) { -
dougdaulton created this gist
Mar 8, 2016 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,33 @@ /* 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' );