Skip to content

Instantly share code, notes, and snippets.

@jeffward3283
Created January 20, 2015 13:27
Show Gist options
  • Save jeffward3283/bd413e0cbec9be0d4dba to your computer and use it in GitHub Desktop.
Save jeffward3283/bd413e0cbec9be0d4dba to your computer and use it in GitHub Desktop.
<?php
/////////////////////////////
# Register Post Type
/////////////////////////////
add_action('init', 'register_post_type_review');
function register_post_type_review(){
# NOTE: to enable comments for your custom post type, you must set the option 'default_comment_status' to true: update_option('default_comment_status', true);
// or goto: WP ADMIN => SETTINGS => DISCUSSION => check the "Allow people to post comments on new articles"
$post_types = array('review');
if(!empty($post_types)){
foreach($post_types as $slug){
register_post_type(
$slug,
array(
'labels' => array(
'name' => __( 'Reviews', TEXTDOMAIN ), // this name will be used when will will call the investments in our theme
'menu_name' => __( 'Reviews', TEXTDOMAIN ),
'singular_name' => __( 'Review', TEXTDOMAIN ),
'add_new' => __( 'Add New', TEXTDOMAIN ),
'add_new_item' => __('Add New Review', TEXTDOMAIN), // custom name to show up instead of Add New Post. Same for the following
'name_admin_bar' => __('Add New Review', TEXTDOMAIN), // custom name to show up instead of Add New Post. Same for the following
'all_items' => __('All Reviews', TEXTDOMAIN),
'edit_item' => __('Edit Review', TEXTDOMAIN),
'new_item' => __('New Review', TEXTDOMAIN),
'view_item' => __('View Review', TEXTDOMAIN),
'search_items' => __('Search Reviews', TEXTDOMAIN),
'not_found' => __('No Reviews Found', TEXTDOMAIN),
'not_found_in_trash' => __('No Reviews Found in Trash', TEXTDOMAIN),
'parent_item_colon' => __('Parent Page', TEXTDOMAIN),
),
'public' => true, // how the type is visible to authors
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'show_ui' => true, // display in admin area
'show_in_menu' => true, // display in admin menu
'show_in_nav_menus' => true, // display in admin menu
'show_in_admin_bar' => true, // display in admin bar
'menu_position' => 5, // 5 - below posts
// 'menu_icon' => 'dashicons-editor-code',
'menu_icon' => 'dashicons-portfolio',
'capability_type' => 'post', // will act like a normal post
'hierarchical' => false, // it means we cannot have parent and sub pages
// 'rewrite' => array( 'slug' => 'slug-goes-here/yes' ),
'rewrite' => true,
'query_var' => true,
'can_export' => true,
'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments' ), // title, editor, author, thumbnail, excerpt, trackbacks, custom-fields, comments, revisions, page-attributes, post-formats
'taxonomies' => array($slug. '_tag', $slug. '_category'), // Adding Categories Boxes
'capabilities' => array(
'read_post' => 'read',
'edit_post' => 'read',
'edit_posts' => 'read',
'edit_others_posts' => 'administrator',
'publish_posts' => 'administrator',
'read_private_posts' => 'read',
'delete_posts' => 'administrator',
'delete_others_posts' => 'administrator',
'delete_post' => 'administrator',
),
)
);
} // endforeach
} // endif
}
?>
<?php
/////////////////////////////
# Register Taxonomies
/////////////////////////////
add_action( 'init', 'register_taxonomies_review', 0 );
function register_taxonomies_review() {
//////////////////////
# Review Categories
//////////////////////
$slug = 'review_category';
$post_types = array('review');
$labels = array(
'menu_name' => __( 'Categories', TEXTDOMAIN ),
'name' => _x( 'Categories', 'taxonomy general name' ),
'singular_name' => _x( 'Review Category', 'taxonomy singular name' ),
'search_items' => __( 'Search Categories', TEXTDOMAIN ),
'all_items' => __( 'All Categories', TEXTDOMAIN ),
'parent_item' => __( 'Parent Category', TEXTDOMAIN ),
'parent_item_colon' => __( 'Parent Category:', TEXTDOMAIN ),
'edit_item' => __( 'Edit Category', TEXTDOMAIN ),
'update_item' => __( 'Update Category', TEXTDOMAIN ),
'add_new_item' => __( 'Add New Category', TEXTDOMAIN ),
'new_item_name' => __( 'New Category Name', TEXTDOMAIN ),
);
$args = array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'slug' => $slug ),
);
register_taxonomy( $slug, $post_types, $args );
//////////////////
# Review Tags
//////////////////
$slug = 'review_tag';
$post_types = array('review');
$labels = array(
'menu_name' => __( 'Tags', TEXTDOMAIN ),
'name' => _x( 'Tags', 'taxonomy general name' ),
'singular_name' => _x( 'Tag', 'taxonomy singular name' ),
'search_items' => __( 'Search Tags', TEXTDOMAIN ),
'popular_items' => __( 'Popular Tags', TEXTDOMAIN ),
'all_items' => __( 'All Tags', TEXTDOMAIN ),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __( 'Edit Tag', TEXTDOMAIN ),
'update_item' => __( 'Update Tag', TEXTDOMAIN ),
'add_new_item' => __( 'Add New Tag', TEXTDOMAIN ),
'new_item_name' => __( 'New Tag Name', TEXTDOMAIN ),
'separate_items_with_commas' => __( 'Separate tags with commas', TEXTDOMAIN ),
'add_or_remove_items' => __( 'Add or remove tags', TEXTDOMAIN ),
'choose_from_most_used' => __( 'Choose from the most used tags', TEXTDOMAIN ),
'not_found' => __( 'No tags found.', TEXTDOMAIN ),
);
$args = array(
'hierarchical' => false,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'update_count_callback' => '_update_post_term_count',
'query_var' => true,
'rewrite' => array( 'slug' => $slug ),
);
register_taxonomy( $slug, $post_types, $args );
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment