Return to Snippet

Revision: 46434
at June 3, 2011 23:22 by nathanbweb


Updated Code
// Register Custom Post Type
// snippet updated 6/3/2011

// Bare Bones
// -- from Ian Stewart at bit.ly/wppoweredby
function powered_by_create_post_type() {
    register_post_type( 'foo', array(
            'public' => true,
        ) );
}
add_action( 'init', 'powered_by_create_post_type' );

// Basic and Quick
// -- from Konstantin Kovshenin at bit.ly/kovcpt
// -- also see Justin Tadlock at bit.ly/jtadcpt
// -- and Custom Post Type Generator at bit.ly/generate-wpcpt

    // Fire this during init
    register_post_type('foo', array(
    'label' => __('Foos'),
    'singular_label' => __('Foo'),
    'public' => true,
    'show_ui' => true,
    'capability_type' => 'post',
    'hierarchical' => false,
    'rewrite' => false,
    'query_var' => false,
    'supports' => array('title', 'editor', 'author', 'excerpt', 'custom-fields')
    ));

// Full and Comprehensive
// -- generated with the Custom Post Type Generator at bit.ly/generate-wpcpt

    add_action( 'init', 'register_cpt_foo' );
    function register_cpt_foo() {
    $labels = array(
    'name' => _x( 'Foos', 'foo' ),
    'singular_name' => _x( 'foo', 'foo' ),
    'add_new' => _x( 'Add New', 'foo' ),
    'add_new_item' => _x( 'Add New foo', 'foo' ),
    'edit_item' => _x( 'Edit foo', 'foo' ),
    'new_item' => _x( 'New foo', 'foo' ),
    'view_item' => _x( 'View foo', 'foo' ),
    'search_items' => _x( 'Search Foos', 'foo' ),
    'not_found' => _x( 'No foos found', 'foo' ),
    'not_found_in_trash' => _x( 'No foos found in Trash', 'foo' ),
    'parent_item_colon' => _x( 'Parent foo:', 'foo' ),
    'menu_name' => _x( 'Foos', 'foo' ),
    );
    $args = array(
    'labels' => $labels,
    'hierarchical' => true,
    'description' => 'These are foos.',
    'supports' => array( 'title', 'editor', 'excerpt', 'author', 'custom-fields' ),
    'taxonomies' => array( 'category' ),
    'public' => true,
    'show_ui' => true,
    'show_in_menu' => true,
    'show_in_nav_menus' => true,
    'publicly_queryable' => true,
    'exclude_from_search' => false,
    'has_archive' => true,
    'query_var' => true,
    'can_export' => true,
    'rewrite' => true,
    'capability_type' => 'post'
    );
    register_post_type( 'foo', $args );
    }
// end

Revision: 46433
at June 3, 2011 23:21 by nathanbweb


Updated Code
// Register Custom Post Type
// snippet updated 6/3/2011

// Bare Bones
// -- from Ian Stewart at bit.ly/wppoweredby
function powered_by_create_post_type() {
    register_post_type( 'pb_tps_reports', array(
            'public' => true,
        ) );
}
add_action( 'init', 'powered_by_create_post_type' );

// Basic and Quick
// -- from Konstantin Kovshenin at bit.ly/kovcpt
// -- also see Justin Tadlock at bit.ly/jtadcpt
// -- and Custom Post Type Generator at bit.ly/generate-wpcpt

    // Fire this during init
    register_post_type('foo', array(
    'label' => __('Foos'),
    'singular_label' => __('Foo'),
    'public' => true,
    'show_ui' => true,
    'capability_type' => 'post',
    'hierarchical' => false,
    'rewrite' => false,
    'query_var' => false,
    'supports' => array('title', 'editor', 'author', 'excerpt', 'custom-fields')
    ));

// Full and Comprehensive
// -- generated with the Custom Post Type Generator at bit.ly/generate-wpcpt

    add_action( 'init', 'register_cpt_foo' );
    function register_cpt_foo() {
    $labels = array(
    'name' => _x( 'Foos', 'foo' ),
    'singular_name' => _x( 'foo', 'foo' ),
    'add_new' => _x( 'Add New', 'foo' ),
    'add_new_item' => _x( 'Add New foo', 'foo' ),
    'edit_item' => _x( 'Edit foo', 'foo' ),
    'new_item' => _x( 'New foo', 'foo' ),
    'view_item' => _x( 'View foo', 'foo' ),
    'search_items' => _x( 'Search Foos', 'foo' ),
    'not_found' => _x( 'No foos found', 'foo' ),
    'not_found_in_trash' => _x( 'No foos found in Trash', 'foo' ),
    'parent_item_colon' => _x( 'Parent foo:', 'foo' ),
    'menu_name' => _x( 'Foos', 'foo' ),
    );
    $args = array(
    'labels' => $labels,
    'hierarchical' => true,
    'description' => 'These are foos.',
    'supports' => array( 'title', 'editor', 'excerpt', 'author', 'custom-fields' ),
    'taxonomies' => array( 'category' ),
    'public' => true,
    'show_ui' => true,
    'show_in_menu' => true,
    'show_in_nav_menus' => true,
    'publicly_queryable' => true,
    'exclude_from_search' => false,
    'has_archive' => true,
    'query_var' => true,
    'can_export' => true,
    'rewrite' => true,
    'capability_type' => 'post'
    );
    register_post_type( 'foo', $args );
    }
// end

Revision: 46432
at May 25, 2011 03:32 by nathanbweb


Updated Code
// Register Custom Post Type
// snippet updated 5/24/2011

// Basic and Quick
// -- from Konstantin Kovshenin at bit.ly/kovcpt
// -- also see Justin Tadlock at bit.ly/jtadcpt
// -- and Custom Post Type Generator at bit.ly/generate-wpcpt

    // Fire this during init
    register_post_type('foo', array(
    'label' => __('Foos'),
    'singular_label' => __('Foo'),
    'public' => true,
    'show_ui' => true,
    'capability_type' => 'post',
    'hierarchical' => false,
    'rewrite' => false,
    'query_var' => false,
    'supports' => array('title', 'editor', 'author', 'excerpt', 'custom-fields')
    ));

// Full and Comprehensive
// -- generated with the Custom Post Type Generator at bit.ly/generate-wpcpt

    add_action( 'init', 'register_cpt_foo' );
    function register_cpt_foo() {
    $labels = array(
    'name' => _x( 'Foos', 'foo' ),
    'singular_name' => _x( 'foo', 'foo' ),
    'add_new' => _x( 'Add New', 'foo' ),
    'add_new_item' => _x( 'Add New foo', 'foo' ),
    'edit_item' => _x( 'Edit foo', 'foo' ),
    'new_item' => _x( 'New foo', 'foo' ),
    'view_item' => _x( 'View foo', 'foo' ),
    'search_items' => _x( 'Search Foos', 'foo' ),
    'not_found' => _x( 'No foos found', 'foo' ),
    'not_found_in_trash' => _x( 'No foos found in Trash', 'foo' ),
    'parent_item_colon' => _x( 'Parent foo:', 'foo' ),
    'menu_name' => _x( 'Foos', 'foo' ),
    );
    $args = array(
    'labels' => $labels,
    'hierarchical' => true,
    'description' => 'These are foos.',
    'supports' => array( 'title', 'editor', 'excerpt', 'author', 'custom-fields' ),
    'taxonomies' => array( 'category' ),
    'public' => true,
    'show_ui' => true,
    'show_in_menu' => true,
    'show_in_nav_menus' => true,
    'publicly_queryable' => true,
    'exclude_from_search' => false,
    'has_archive' => true,
    'query_var' => true,
    'can_export' => true,
    'rewrite' => true,
    'capability_type' => 'post'
    );
    register_post_type( 'foo', $args );
    }
// end

Revision: 46431
at May 19, 2011 05:21 by nathanbweb


Initial Code
// via bit.ly/kovcpt
// or see bit.ly/jtadcpt

// Fire this during init
register_post_type('foo', array(
	'label' => __('Foos'),
	'singular_label' => __('Foo'),
	'public' => true,
	'show_ui' => true,
	'capability_type' => 'post',
	'hierarchical' => false,
	'rewrite' => false,
	'query_var' => false,
	'supports' => array('title', 'editor', 'author', 'excerpt', 'custom-fields')
));

Initial URL
http://bit.ly/kovcpt

Initial Description

                                

Initial Title
WordPress register custom post type code

Initial Tags
post, wordpress

Initial Language
PHP