Skip to content

Instantly share code, notes, and snippets.

Created October 22, 2012 15:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/3932136 to your computer and use it in GitHub Desktop.
Save anonymous/3932136 to your computer and use it in GitHub Desktop.
CPT Registration, not working
<?php
define('BAPT_CPT', 'b_affiliate');
define('BAPT_CTAX', 'b_aff_categories');
class B_Affiliate_Post_Type {
function initialize(){
add_action( 'init', array($this, '_init') );
}
function _init(){
if(is_admin()){
$this->_register_cpt();
$this->_register_taxonomy();
}
}
function _register_cpt(){
$labels = array(
'name' => _x( 'Affiliates', BAPT_CPT ),
'singular_name' => _x( 'Affiliate', BAPT_CPT ),
'add_new' => _x( 'Add New', BAPT_CPT ),
'add_new_item' => _x( 'Add New Affiliate', BAPT_CPT ),
'edit_item' => _x( 'Edit Affiliate', BAPT_CPT ),
'new_item' => _x( 'New Affiliate', BAPT_CPT ),
'view_item' => _x( 'View Affiliate', BAPT_CPT ),
'search_items' => _x( 'Search Affiliates', BAPT_CPT ),
'not_found' => _x( 'No affiliates found', BAPT_CPT ),
'not_found_in_trash' => _x( 'No affiliates found in Trash', BAPT_CPT ),
'parent_item_colon' => _x( 'Parent Affiliate:', BAPT_CPT ),
'menu_name' => _x( 'Affiliates', BAPT_CPT ),
);
$args = array(
'labels' => $labels,
'hierarchical' => false,
'description' => 'Affiliate Custom Post Type',
'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'page-attributes' ),
'taxonomies' => array( BAPT_CTAX ),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 20,
'show_in_nav_menus' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'has_archive' => true,
'can_export' => true,
'rewrite' => array('slug' => 'listing', 'with_front' => false),
'capability_type' => 'post'
);
register_post_type( BAPT_CPT, $args );
}
function _register_taxonomy(){
$labels = array(
'name' => _x( 'Affiliate Categories', BAPT_CTAX ),
'singular_name' => _x( 'Affiliate Category', BAPT_CTAX ),
'search_items' => _x( 'Search Affiliate Categories', BAPT_CTAX ),
'popular_items' => _x( 'Popular Affiliate Categories', BAPT_CTAX ),
'all_items' => _x( 'All Affiliate Categories', BAPT_CTAX ),
'parent_item' => _x( 'Parent Affiliate Category', BAPT_CTAX ),
'parent_item_colon' => _x( 'Parent Affiliate Category:', BAPT_CTAX ),
'edit_item' => _x( 'Edit Affiliate Category', BAPT_CTAX ),
'update_item' => _x( 'Update Affiliate Category', BAPT_CTAX ),
'add_new_item' => _x( 'Add New Affiliate Category', BAPT_CTAX ),
'new_item_name' => _x( 'New Affiliate Category', BAPT_CTAX ),
'separate_items_with_commas' => _x( 'Separate affiliate categories with commas', BAPT_CTAX ),
'add_or_remove_items' => _x( 'Add or remove affiliate categories', BAPT_CTAX ),
'choose_from_most_used' => _x( 'Choose from the most used affiliate categories', BAPT_CTAX ),
'menu_name' => _x( 'Affiliate Categories', BAPT_CTAX ),
);
$args = array(
'labels' => $labels,
'public' => true,
'show_in_nav_menus' => true,
'show_ui' => true,
'show_tagcloud' => false,
'hierarchical' => true,
'rewrite' => array(
'slug' => 'listing-categories',
'with_front' => false,
'hierarchical' => true
),
'query_var' => true
);
register_taxonomy( BAPT_CTAX, array(BAPT_CPT), $args );
}
}
$bapt_plugin = new B_Affiliate_Post_Type();
$bapt_plugin->initialize();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment