Created
November 28, 2013 13:04
-
-
Save vajrasar/7691543 to your computer and use it in GitHub Desktop.
probques
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 | |
/*****Creating CPT and Taxos for Events [START]******************/ | |
function my_custom_post_events() { | |
$labels = array( | |
'name' => _x( 'Events', 'post type general name' ), | |
'singular_name' => _x( 'Event', 'post type singular name' ), | |
'add_new' => _x( 'Add New', 'book' ), | |
'add_new_item' => __( 'Add New Event' ), | |
'edit_item' => __( 'Edit Event' ), | |
'new_item' => __( 'New Event' ), | |
'all_items' => __( 'All Events' ), | |
'view_item' => __( 'View Events' ), | |
'search_items' => __( 'Search Events' ), | |
'not_found' => __( 'No Events found' ), | |
'not_found_in_trash' => __( 'No Events found in the Trash' ), | |
'parent_item_colon' => '', | |
'menu_name' => 'Events' | |
); | |
$args = array( | |
'labels' => $labels, | |
'description' => 'Holds all Events kind of News', | |
'public' => true, | |
'menu_position' => 6, | |
'supports' => array( 'title', 'thumbnail', 'comments' ), | |
'has_archive' => 'events', | |
'rewrite' => array( 'slug' => 'events/%event_cpt_category%', 'with_front' => false ), | |
); | |
register_post_type( 'events', $args ); | |
flush_rewrite_rules(); | |
} | |
add_action( 'init', 'my_custom_post_events' ); | |
/****Creating Custom Post Types of Classifieds Ends****/ | |
/****Creating Custom Taxonomies for Classifieds *****/ | |
function my_taxonomies_event_category() { | |
$labels = array( | |
'name' => _x( 'Event Categories', 'taxonomy general name' ), | |
'singular_name' => _x( 'Event Category', 'taxonomy singular name' ), | |
'search_items' => __( 'Search Event Categories' ), | |
'all_items' => __( 'All Event Categories' ), | |
'parent_item' => __( 'Parent Event Category' ), | |
'parent_item_colon' => __( 'Parent Event Category:' ), | |
'edit_item' => __( 'Edit Event Category' ), | |
'update_item' => __( 'Update Event Category' ), | |
'add_new_item' => __( 'Add New Event Category' ), | |
'new_item_name' => __( 'New Event Category' ), | |
'menu_name' => __( 'Event Categories' ), | |
); | |
$args = array( | |
'labels' => $labels, | |
'hierarchical' => true, | |
'rewrite' => array( 'slug' => 'events', 'with_front' => false ), | |
); | |
register_taxonomy( 'event_cpt_category', 'events', $args ); | |
} | |
add_action( 'init', 'my_taxonomies_event_category', 0 ); | |
function my_taxonomies_event_tag() { | |
$labels = array( | |
'name' => _x( 'Event Tags', 'taxonomy general name' ), | |
'singular_name' => _x( 'Event Tag', 'taxonomy singular name' ), | |
'search_items' => __( 'Search Event Tags' ), | |
'all_items' => __( 'All Event Tags' ), | |
'parent_item' => __( 'Parent Event Tag' ), | |
'parent_item_colon' => __( 'Parent Event Tag:' ), | |
'edit_item' => __( 'Edit Event Tag' ), | |
'update_item' => __( 'Update Event Tag' ), | |
'add_new_item' => __( 'Add New Event Tag' ), | |
'new_item_name' => __( 'New Event Tag' ), | |
'menu_name' => __( 'Event Tags' ), | |
); | |
$args = array( | |
'labels' => $labels, | |
'hierarchical' => false, | |
); | |
register_taxonomy( 'event_cpt_tag', 'events', $args ); | |
} | |
add_action( 'init', 'my_taxonomies_event_tag', 0 ); | |
/************************************************/ | |
add_filter('post_type_link', 'events_permalink_structure', 10, 4); | |
function events_permalink_structure($post_link, $post, $leavename, $sample) | |
{ | |
if ( false !== strpos( $post_link, '%event_cpt_category%' ) ) | |
{ | |
$event_type_term = get_the_terms( $post->ID, 'event_cpt_category' ); | |
if(is_array($event_type_term) && !empty($event_type_term)) | |
{ | |
$post_link = str_replace( '%event_cpt_category%', array_pop( $event_type_term )->slug, $post_link ); | |
} | |
} | |
return $post_link; | |
} | |
/*****Creating CPT and Taxos for Eevents [END]******************/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment