我无法获取自定义帖子类型和网址的网址结构。分类。我有一个名为项目的自定义帖子类型和公司的分类,我创建了项目并将它们添加到公司分类中。
公司分类标准包括设计,电影,广告和广告。架构,所以当我访问一个项目时,我希望URL为websitename / film / projects / projectname,但目前我只有websitename / projects / projectname
这是我注册的自定义帖子类型“电影”和分类“流派”
// Register Custom Post Type
function movies() {
$labels = array(
'name' => _x( 'Movies', 'Post Type General Name', 'text_domain' ),
'singular_name' => _x( 'Movie', 'Post Type Singular Name', 'text_domain' ),
'menu_name' => __( 'Movies', 'text_domain' ),
'name_admin_bar' => __( 'Movies', 'text_domain' ),
'archives' => __( 'Movie Archives', 'text_domain' ),
'attributes' => __( 'Movie Attributes', 'text_domain' ),
'parent_item_colon' => __( 'Parent Item:', 'text_domain' ),
'all_items' => __( 'All Movies', 'text_domain' ),
'add_new_item' => __( 'Add New Item', 'text_domain' ),
'add_new' => __( 'Add New', 'text_domain' ),
'new_item' => __( 'New Item', 'text_domain' ),
'edit_item' => __( 'Edit Item', 'text_domain' ),
'update_item' => __( 'Update Item', 'text_domain' ),
'view_item' => __( 'View Item', 'text_domain' ),
'view_items' => __( 'View Items', 'text_domain' ),
'search_items' => __( 'Search Item', 'text_domain' ),
'not_found' => __( 'Not found', 'text_domain' ),
'not_found_in_trash' => __( 'Not found in Trash', 'text_domain' ),
'featured_image' => __( 'Featured Image', 'text_domain' ),
'set_featured_image' => __( 'Set featured image', 'text_domain' ),
'remove_featured_image' => __( 'Remove featured image', 'text_domain' ),
'use_featured_image' => __( 'Use as featured image', 'text_domain' ),
'insert_into_item' => __( 'Insert into item', 'text_domain' ),
'uploaded_to_this_item' => __( 'Uploaded to this item', 'text_domain' ),
'items_list' => __( 'Items list', 'text_domain' ),
'items_list_navigation' => __( 'Items list navigation', 'text_domain' ),
'filter_items_list' => __( 'Filter items list', 'text_domain' ),
);
$args = array(
'label' => __( 'Movie', 'text_domain' ),
'description' => __( 'Movie Description', 'text_domain' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'thumbnail', 'page-attributes', 'post-formats' ),
'taxonomies' => array( 'genres'),
array(
'rewrite' => array( 'slug' => 'movies/%genres%', 'with_front' => false ),
'has_archive' => 'genres',
// your other args...
),
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'page',
);
register_post_type( 'movies', $args );
}
add_action( 'init', 'movies', 0 );
// Register Custom Taxonomy
function genres() {
$labels = array(
'name' => _x( 'Genres', 'Taxonomy General Name', 'text_domain' ),
'singular_name' => _x( 'Genre', 'Taxonomy Singular Name', 'text_domain' ),
'menu_name' => __( 'Genre', 'text_domain' ),
'all_items' => __( 'All Genres', 'text_domain' ),
'parent_item' => __( 'Parent Item', 'text_domain' ),
'parent_item_colon' => __( 'Parent Item:', 'text_domain' ),
'new_item_name' => __( 'New Item Name', 'text_domain' ),
'add_new_item' => __( 'Add New Item', 'text_domain' ),
'edit_item' => __( 'Edit Item', 'text_domain' ),
'update_item' => __( 'Update Item', 'text_domain' ),
'view_item' => __( 'View Item', 'text_domain' ),
'separate_items_with_commas' => __( 'Separate items with commas', 'text_domain' ),
'add_or_remove_items' => __( 'Add or remove items', 'text_domain' ),
'choose_from_most_used' => __( 'Choose from the most used', 'text_domain' ),
'popular_items' => __( 'Popular Items', 'text_domain' ),
'search_items' => __( 'Search Items', 'text_domain' ),
'not_found' => __( 'Not Found', 'text_domain' ),
'no_terms' => __( 'No items', 'text_domain' ),
'items_list' => __( 'Items list', 'text_domain' ),
'items_list_navigation' => __( 'Items list navigation', 'text_domain' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'public' => true,
'show_ui' => true,
array(
'rewrite' => array( 'slug' => 'movies', 'with_front' => false ),
// your other args...
),
'query_var' => true,
'publicly_queryable' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => true,
);
register_taxonomy( 'genres', array( 'post', 'page', 'movies' ), $args );
}
add_action( 'init', 'genres', 0 );
function wpa_show_permalinks( $post_link, $post ){
if ( is_object( $post ) && $post->post_type == 'movies' ){
$terms = wp_get_object_terms( $post->ID, 'genres' );
if( $terms ){
return str_replace( '%genres%' , $terms[0]->slug , $post_link );
}
}
return $post_link;
}
add_filter( 'post_type_link', 'wpa_show_permalinks', 1, 2 );
这是我的自定义分类法“Genres”