Skip to content

Instantly share code, notes, and snippets.

@acedesigns
Last active April 19, 2016 22:17
Show Gist options
  • Save acedesigns/a8d5ebbf31c6b42cd3dcb54ffbf18014 to your computer and use it in GitHub Desktop.
Save acedesigns/a8d5ebbf31c6b42cd3dcb54ffbf18014 to your computer and use it in GitHub Desktop.
A generic functions file for WP theme, When creating custom Post Types
<?php
/*
Shout Out to :
http://stackoverflow.com/questions/27896131
http://webexplorar.com/wordpress-create-custom-post-types-with-tags-and-categories
*/
add_action ('init', 'register_custom_post_type_event');
function register_custom_post_type_event() {
$labels = array(
'name' => _x('Event', 'post type general name'),
'singular_name' => _x('Event', 'post type singular name'),
'add_new' => _x('Add Event', 'event'),
'add_new_item' => __('Add New Event'),
'edit_item' => __('Edit Event'),
'new_item' => __('New Event'),
'all_items' => __('All Events'),
'view_item' => __('View Event'),
'search_items' => __('Search Events'),
'not_found' => __('No Events found'),
'not_found_in_trash' => __('No Events found in Trash'),
'parent_item_colon' => '',
'menu_name' => __('Event')
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array('slug' => 'event'),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => true,
'menu_position' => null,
'supports' => array('title', 'editor', 'excerpt', 'thumbnail', 'author')
);
register_post_type('event', $args);
register_taxonomy( 'event_categories', array('event'), array(
'hierarchical' => true,
'label' => 'Event Categories',
'singular_label' => 'Event Category',
'rewrite' => array( 'slug' => 'categories', 'with_front'=> false )
)
);
register_taxonomy_for_object_type( 'event_categories', 'event' );
}
add_action( 'init', 'event_tag_taxonomies' ); //change order add_action( 'init', 'news_tag_taxonomies', 0 );
function event_tag_taxonomies() {
// Add new taxonomy, NOT hierarchical (like tags)
$labels = array(
'name' => _x( 'Event Tags', 'taxonomy general name' ),
'singular_name' => _x( 'Tag', 'taxonomy singular name' ),
'search_items' => __( 'Search Tags' ),
'popular_items' => __( 'Popular Tags' ),
'all_items' => __( 'All Tags' ),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __( 'Edit Tag' ),
'update_item' => __( 'Update Tag' ),
'add_new_item' => __( 'Add New Tag' ),
'new_item_name' => __( 'New Tag Name' ),
'separate_items_with_commas' => __( 'Separate tags with commas' ),
'add_or_remove_items' => __( 'Add or remove tags' ),
'choose_from_most_used' => __( 'Choose from the most used tags' ),
'menu_name' => __( 'Event Tags' ),
);
register_taxonomy('event_tag','event',array(
'hierarchical' => false,
'labels' => $labels,
'show_ui' => true,
'update_count_callback' => '_update_post_term_count',
'query_var' => true,
'rewrite' => array( 'slug' => 'tag' ),
));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment