Project Custom Post Type (CPT) and Custom Taxonomies

In creating this portfolio site, I wanted to be able to showcase my WordPress chops (of creating custom post types and custom taxonomies) and also be able to showcase other projects I’ve worked on.

Needs

To have a custom post type for this portfolio site to help better display and classify projects that I’ve worked on. It should display information from custom taxonomies related to about-ness, jobs, and degrees and display the completion date of the project, if included.

Implementation

Both the taxonomies and CPT were created as mu-plugins so they will exist with the project no matter the theme applied.

Creating the Taxonomies

  • Created 3 taxonomies: about, job, and degree.
  • The about taxonomy was created hierarchical so topics could be nested within each other. E.g.:
  • The job and degree taxonomies are not hierarchical.

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'
										   ),
  ) );