Need help with Custom Taxonomy + Custom Post Type

Question

I am trying to get the URL working for custom post type "our-work" without success. When I created custom post type (our-work) post and assign to custom category sustainability and check the post to be not found.
The url address does not appear to be like this our-work/sustainability/project-post-name but our-work/project-name-project. Could anyone correct me on this code and why it not working?

// Project Custom Post
 function create_post_type() {
    register_post_type( 'our-work',
        array(
            'labels' => array(
                'name'=> _('Our Work'),
                'singular_name' => _('Our Work')
             ),
            'public' => true,
            'has_archive' => true,
            'taxonomies'  => array( 'projects' ),
            'hierarchical'        => true,
            'capability_type'     => 'post',
             'publicly_queryable'  => true,
            'show_in_nav_menus'   => true,
             'show_in_menu'        => true,
            'supports'            => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'revisions', ),
        )
    );
}
add_action( 'init', 'create_post_type' );

//hook into the init action and call create_book_taxonomies when it fires
 
add_action( 'init', 'create_subjects_hierarchical_taxonomy', 0 );
 
//create a custom taxonomy name it subjects for your posts
 
function create_subjects_hierarchical_taxonomy() {
 
// Add new taxonomy, make it hierarchical like categories
//first do the translations part for GUI
 
  $labels = array(
    'name' => _x( 'Projects', 'taxonomy general name' ),
    'singular_name' => _x( 'Project', 'taxonomy singular name' ),
    'search_items' =>  __( 'Search Project' ),
    'all_items' => __( 'All Projects' ),
    'parent_item' => __( 'Parent Project' ),
    'parent_item_colon' => __( 'Parent Project:' ),
    'edit_item' => __( 'Edit Subject' ), 
    'update_item' => __( 'Update Subject' ),
    'add_new_item' => __( 'Add New Subject' ),
    'new_item_name' => __( 'New Subject Name' ),
    'menu_name' => __( 'Projects' ),
  );    
 
// Now register the taxonomy
  register_taxonomy('projects',array('our-work'), array(
    'hierarchical' => true,
    'labels' => $labels,
    'show_ui' => true,
    'show_in_rest' => true,
    'show_admin_column' => true,
    'query_var' => true,
    'rewrite' => array( 'slug' => 'our-work' ),
  ));
 
}
0
William Jerome 8 months 2020-12-13T17:11:31-05:00 0 Answers 17 views 0

Leave an answer

Browse
Browse