Permalink Probleme mit benutzerdefinierten Post-Typ

Ich habe einen benutzerdefinierten Post-Typ namens “Arbeit” und es hat eine Taxonomie namens “Kategorien”. Derzeit funktioniert “/ work” und “/ work / category_slug / work_slug” großartig. “/ Work / category_slug” jedoch nicht. Ich bekomme eine 404-Seite. Irgendwelche Ideen, was ich tun kann?

register_post_type('work', array( 'label' => 'Work', 'description' => '', 'public' => true, 'show_ui' => true, 'show_in_menu' => true, 'capability_type' => 'post', 'map_meta_cap' => true, 'hierarchical' => false, 'rewrite' => array('slug' => 'work', 'with_front' => true), 'query_var' => true, 'has_archive' => true, 'supports' => array('title','editor','custom-fields','comments','revisions','page-attributes'), 'taxonomies' => array('categories'), 'labels' => array ( 'name' => 'Work', 'singular_name' => 'work', 'menu_name' => 'Work', 'add_new' => 'Add New', 'add_new_item' => 'Add New Item', 'edit' => 'Edit ', 'edit_item' => 'Edit Item', 'new_item' => 'New Item', 'view' => 'View', 'view_item' => 'View Item', 'search_items' => 'Search Items', 'not_found' => 'No Work Items Found', 'not_found_in_trash' => 'No Work Items found in Trash', 'parent' => 'Parent Work Item', ) ) ); register_taxonomy( 'categories',array ( 0 => 'work', ), array( 'hierarchical' => true, 'label' => 'Categories', 'show_ui' => true, 'query_var' => true, 'show_admin_column' => false, 'labels' => array ( 'search_items' => 'Category', 'popular_items' => '', 'all_items' => '', 'parent_item' => '', 'parent_item_colon' => '', 'edit_item' => '', 'update_item' => '', 'add_new_item' => '', 'new_item_name' => '', 'separate_items_with_commas' => '', 'add_or_remove_items' => '', 'choose_from_most_used' => '', ) ) ); 

Solutions Collecting From Web of "Permalink Probleme mit benutzerdefinierten Post-Typ"

Es sollte ” categories/category_slug ” sein, nicht ” work/category_slug ” für die Kategorie archieve page

Fügen Sie diesen Code Ihrer functions.php hinzu.

 // Include Custom Post Types on Tags and Categories Archive Pages add_filter('pre_get_posts', 'query_post_type'); function query_post_type($query) { if(is_category() || is_tag() || is_taxonomy()) { $post_type = get_query_var('post_type'); if($post_type) $post_type = $post_type; else $post_type = array('work', 'post'); // replace cpt to your custom post type $query->set('post_type',$post_type); return $query; } }