Skip to content

Instantly share code, notes, and snippets.

@alimoshen
Created January 29, 2018 23:21
Embed
What would you like to do?
Custom post type registration
// Post type 'expertise'
add_action( 'init', 'create_expertise_post_type', 4 );
function create_expertise_post_type()
{
$labels = array(
'name' => __( 'Expertise' ),
'singular_name' => __( 'Expertise' ),
'add_new' => __( 'Add New' ),
'add_new_item' => __( 'Create New' ),
'edit' => __( 'Edit' ),
'edit_item' => __( 'Edit' ),
'new_item' => __( 'New' ),
'view' => __( 'View' ),
'view_item' => __( 'View' ),
'search_items' => __( 'Search' ),
'not_found' => __( 'Not found' ),
'not_found_in_trash' => __( 'Nothing found in trash' ),
'parent' => __( 'Parent' ),
);
$args = array(
'labels' => $labels,
'description' => __( 'This is where you can create a new Item.' ),
'public' => true,
'show_ui' => true,
'capability_type' => 'post',
'publicly_queryable' => true,
'exclude_from_search' => false,
'menu_position' => 4,
'hierarchical' => true,
'_builtin' => false, // It's a custom post type, not built in!
'rewrite' => array( 'slug' => 'expertise/%expertise_type%', 'with_front' => true ),
'query_var' => true,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt' ),
'taxonomies' => array('expertise_type'),
);
register_post_type('expertise',$args);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment