I set up a custom post type and taxonomy for Person
which worked fine. I added quite a few posts until I decided I wanted to change the name to People
. The posts I had added disappeared so I had to reassign the posts to the correct post type.
The problem I have now is the taxonomies are not displaying (location and job-function ). They don't appear to be registered and don't show in the menu or on the custom type post page.
I have tried resetting permalinks and used flush_rewrite_rules(); but still nothing. Can anyone help?
<?php
/**
* People post type & taxonomies
*
* Post Type: people
* Taxonomies: function
*
*/
add_action( 'init', 'create_people_post_type', 5 );
function create_people_post_type() {
flush_rewrite_rules();
register_post_type( 'People',
[
'labels' => [
'name' => __( 'People' ),
'singular_name' => __( 'People' ),
],
'public' => true,
'has_archive' => true,
'supports' => ['title', 'thumbnail', 'author' ],
]
);
register_taxonomy(
'job-functions',
'People',
[
'labels' => [
'name' => __( 'Job Functions' ),
'singular_name' => __( 'Job Function' ),
],
'hierarchical' => true,
'show_admin_column' => true,
]
);
}
add_action('init','add_locations_to_people');
function add_locations_to_people(){
register_taxonomy_for_object_type('location', 'People');
}
}
<?php
/**
* Location post type
*
* Post Type: location
*
*
*/
add_action( 'init', 'create_office_location_post_type', 4 );
function create_office_location_post_type() {
register_post_type( 'location',
[
'labels' => [
'name' => __( 'Office Locations' ),
'singular_name' => __( 'Office Location' ),
],
'public' => true,
'has_archive' => true,
'supports' => [ 'title', 'author' ],
]
);
}
?>