guillermorangel
12/31/2013 - 10:59 PM

custom post type and taxonomy

custom post type and taxonomy

<?php

// Register Custom Post Types

function project_custom_post_type() {

    $slug = 'project';
    $name_s = 'Our Project';
    $name_p = 'Our Projects';
    $item_s = 'Project';
    $item_p = 'Projects';
    $icon = 'dashicons-clipboard';

    $labels = array(
        'name'                  => $name_p,
        'singular_name'         => $name_s,
        'menu_name'             => $name_p,
        'all_items'             => 'All '.$item_p,
        'view_item'             => 'View '.$item_s,
        'add_new_item'          => 'Add New '.$item_s,
        'add_new'               => 'Add New '.$item_s,
        'edit_item'             => 'Edit '.$item_s,
        'update_item'           => 'Update '.$item_s,
        'search_items'          => 'Search '.$item_p,
        'not_found'             => 'No '. $item_p .' found',
        'not_found_in_trash'    => 'No '. $item_p .' found in Trash',
        'parent_item_colon'     => '',
    );

    $args = array(
        'labels'                => $labels,
        'menu_icon'             => $icon,
        'menu_position'         => 10,                                       /*default below comments*/
        'has_archive'           => true,                                    /*default false*/
        //'rewrite'               => array( 'slug' => $post_type ),         /*default $post_type*/
        //'description'           => 'Almost Heaven Saunas',                  /*default ''*/
        //'taxonomies'            => array( 'practiceareas' ),              /*default 'no taxonomies'*/
        'supports'              => array( 'title', 'editor', 'excerpt', 'thumbnail', 'revisions', 'custom-fields', 'page-attributes', ),
        //'label'                 => $post_type,   /*default $post_type*/
        //'query_var'             => $post_type,   /*default $post_type */
        'public'                => true,          /*default false*/
        //'publicly_queryable'    => true,          /*default public*/
        //'show_in_nav_menus'     => true,          /*default public*/
        //'show_ui'               => true,          /*default public*/
        //'show_in_menu'          => true,          /*default show_ui*/
        //'show_in_admin_bar'     => true,         /*default show_in_menu*/
        //'exclude_from_search'   => false,         /*default !public*/
        //'can_export'            => true,          /*default true*/
        //'hierarchical'          => false,         /*default false*/
        //'capability_type'       => 'post',        /*default post*/
    );
    register_post_type( $slug, $args );
    
    // This adds the normal post categories to your custom post type
    // register_taxonomy_for_object_type( 'category', 'signatureprofile' );
    // This adds the normal post tags to your custom post type
    // register_taxonomy_for_object_type( 'post_tag', 'signatureprofile' );
}

// Hook into the 'init' action
add_action( 'init', 'project_custom_post_type', 0 );



// Register Custom Taxonomy

function project_custom_taxonomy()  {

    $cpt_slug = 'project';
    $tax_slug = 'categories';
    $tax_name_s = 'Category';
    $tax_name_p = 'Categories';

    $labels = array(
        'name'                       => $tax_name_p,
        'singular_name'              => $tax_name_s,
        'menu_name'                  => $tax_name_p,
        'all_items'                  => 'All '.$tax_name_p,
        'parent_item'                => 'Parent '.$tax_name_s,
        'parent_item_colon'          => 'Parent '. $tax_name_s .':',
        'new_item_name'              => 'New '.$tax_name_s,
        'add_new_item'               => 'Add New '.$tax_name_s,
        'edit_item'                  => 'Edit '.$tax_name_s,
        'update_item'                => 'Update '.$tax_name_s,
        'separate_items_with_commas' => 'Separate '. $tax_name_p .' with commas',
        'search_items'               => 'Search '.$tax_name_p,
        'add_or_remove_items'        => 'Add or remove '.$tax_name_p,
        'choose_from_most_used'      => 'Choose from the most used '.$tax_name_p,
    );
    //$rewrite = array(
    //    'slug'                       => $tax_slug,   /*default $taxonomy*/
    //    'with_front'                 => true,               /*default*/
    //    'hierarchical'               => true,              /*default*/
    //);
    $args = array(
        'labels'                     => $labels,
        //'rewrite'                    => $rewrite,
        'hierarchical'               => true,               /*default false*/
        //'query_var'                  => $tax_slug,    /*default $taxonomy*/
        //'public'                     => true,               /*default*/
        //'show_in_nav_menus'          => true,               /*default public*/
        //'show_ui'                    => true,               /*default public*/
        'show_tagcloud'              => false,              /*default show_ui*/
        'show_admin_column'          => true,               /*default false*/
        
    );
    register_taxonomy( $tax_slug, $cpt_slug, $args );
}

// Hook into the 'init' action
add_action( 'init', 'project_custom_taxonomy', 0 );

?>



=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~



<?php

if ( ! function_exists('persons_custom_post_type') ) {

// Register Custom Post Type
function persons_custom_post_type() {

    $labels = array(
        'name'                  => 'Persons',
        'singular_name'         => 'Person',
        'menu_name'             => 'Persons',
        'all_items'             => 'All Persons',
        'view_item'             => 'View Person',
        'add_new_item'          => 'Add New Person',
        'add_new'               => 'New Person',
        'edit_item'             => 'Edit Person',
        'update_item'           => 'Update Person',
        'search_items'          => 'Search Persons',
        'not_found'             => 'No persons found',
        'not_found_in_trash'    => 'No persons found in Trash',
        'parent_item_colon'     => '',
    );
    $args = array(
        'labels'                => $labels,
        'menu_position'         => 10,                                  /*default below comments*/
        'has_archive'           => true,                                /*default false*/
        'rewrite'               => array( 'slug' => 'person' ),         /*default $post_type*/
        'description'           => 'Persons profile and information',   /*default ''*/
        //'taxonomies'            => array( 'practiceareas' ),            /*default 'no taxonomies'*/
        'supports'              => array( 'title', 'editor', 'excerpt', 'thumbnail', 'revisions', 'custom-fields', 'page-attributes', ),
        // 'menu_icon'             => get_stylesheet_directory_uri() . '/includes/images/persons.png',
        'label'                 => 'person',   /*default $post_type*/
        'query_var'             => 'person',   /*default $post_type*/
        'public'                => true,        /*default false*/
        'publicly_queryable'    => true,        /*default public*/
        'show_in_nav_menus'     => true,        /*default public*/
        'show_ui'               => true,        /*default public*/
        'show_in_menu'          => true,        /*default show_ui*/
        'show_in_admin_bar'     => false,       /*default show_in_menu*/
        'exclude_from_search'   => false,       /*default !public*/
        'can_export'            => true,        /*default*/
        'hierarchical'          => false,       /*default*/
        'capability_type'       => 'post',      /*default*/
    );
    register_post_type( 'persons', $args );

    // This adds the normal post categories to your custom post type
    // register_taxonomy_for_object_type( 'category', 'signatureprofile' );
    // This adds the normal post tags to your custom post type
    // register_taxonomy_for_object_type( 'post_tag', 'signatureprofile' );
}

// Hook into the 'init' action
add_action( 'init', 'persons_custom_post_type', 0 );

}


if ( ! function_exists('practice_areas_custom_taxonomy') ) {

// Register Custom Taxonomy
function practice_areas_custom_taxonomy()  {

    $labels = array(
        'name'                       => 'Practice Areas',
        'singular_name'              => 'Practice Area',
        'menu_name'                  => 'Practice Areas',
        'all_items'                  => 'All Practice Areas',
        'parent_item'                => 'Parent Practice Area',
        'parent_item_colon'          => 'Parent Practice Area:',
        'new_item_name'              => 'New Practice Area',
        'add_new_item'               => 'Add New Practice Area',
        'edit_item'                  => 'Edit Practice Area',
        'update_item'                => 'Update Practice Area',
        'separate_items_with_commas' => 'Separate practice areas with commas',
        'search_items'               => 'Search practice areas',
        'add_or_remove_items'        => 'Add or remove practice areas',
        'choose_from_most_used'      => 'Choose from the most used practice areas',
    );
    $rewrite = array(
        'slug'                       => 'practice-area',   /*default $taxonomy*/
        'with_front'                 => true,               /*default*/
        'hierarchical'               => true,              /*default*/
    );
    $args = array(
        'labels'                     => $labels,
        'rewrite'                    => $rewrite,
        'hierarchical'               => true,               /*default false*/
        'query_var'                  => 'practiceareas',    /*default $taxonomy*/
        'public'                     => true,               /*default*/
        'show_in_nav_menus'          => true,               /*default public*/
        'show_ui'                    => true,               /*default public*/
        'show_tagcloud'              => false,              /*default show_ui*/
        'show_admin_column'          => true,               /*default false*/
    );
    register_taxonomy( 'practiceareas', 'persons', $args );
}

// Hook into the 'init' action
// add_action( 'init', 'practice_areas_custom_taxonomy', 0 );

}

?>