Background and Objectives
I wanted to showcase my WordPress chops on this site while displaying a range of completed projects. That meant building a dedicated “Project” custom post type to manage portfolio items, along with the metadata and classification needed to organize them.
Requirements
- A custom post type for portfolio projects
- Multiple custom taxonomies for “about”, “job”, and “degree” classifications
- A field for each project’s completion date
- Functionality that persists across different WordPress themes
Implementation
- Built an “About” taxonomy as a hierarchical structure, allowing nested topics (e.g., Web as a parent term with WordPress as a child)
- Built non-hierarchical “Job” and “Degree” taxonomies
- Registered the custom post type and both taxonomies as mu-plugins so they’d persist independent of the active theme
- Configured the Project post type to support title, editor, author, thumbnail, excerpt, and revisions, and enabled the REST API
- Added an Advanced Custom Fields (ACF) field to track each project’s completion date
Code Snippets
Code to Create the About Taxonomy
register_taxonomy( 'about', array( 'post', 'page', 'project' ), array(
'hierarchical' => true,
'labels' => $about_labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'show_in_rest' => true,
'rewrite' => array(
'slug' => 'about'
)
) );
Creating the Project Custom Post Type (CPT)
- To show the completed date required the creation of an Advanced Custom Field (ACF) for completion date.
register_post_type( 'project', array(
'public' => true,
'labels' => array(
'name' => __('Projects'),
'singular_name' => __('Project'),
'add_new_item' => __('Add New Project'),
'edit_item' => __('Edit Project'),
'all_items' => __('All Projects')
),
'menu_icon' => 'dashicons-list-view',
'show_in_rest' => true,
'supports' => array(
'title',
'editor',
'author',
'thumbnail',
'excerpt',
'revisions'
),
'has_archive' => true,
'rewrite' => array(
'slug' => 'projects'
),
'menu_position' => 9,
'taxonomies' => array(
'job',
'degree',
'about'
),
) );