[英]Custom Post Type URL redirected wrong
I've got some Wordpress CPTs. 我有一些Wordpress CPT。 They correct URL should be /wordpress/training/training-page/, and that's the URL I see in the admin manage page, but when I click the link the URL I end up with is /wordpress/blog/2010/05/21/training-page/.
他们正确的URL应该是/ wordpress / training / training-page /,这是我在管理页面中看到的URL,但是当我单击链接时,最终得到的URL是/ wordpress / blog / 2010/05/21 /培训页/。
I deactivated my plugins with no success. 我没有激活我的插件。 Does anyone know how to keep the correct URL intact?
有人知道如何保持正确的URL完整吗?
Here's my code: 这是我的代码:
<?php
add_action( 'init', 'tv_content_posttype' );
function tv_content_posttype() {
register_taxonomy('content',
'training',
array(
'hierarchical' => true,
'label' => 'Content Index',
'query_var' => true,
'rewrite' => true
)
);
register_post_type( 'training',
array(
'type' => 'page',
'labels' => array(
'name' => __( 'TV Training' ),
'singular_name' => __( 'TV Training' )
),
'public' => true,
'rewrite' => array(
'with_front' => false,
'slug' => 'training',
),
'hierarchical' => true,
'query_var' => true,
'taxonomies' => array( 'content' ),
)
);
}
Just a few observations: there's no such thing as a 'type'
argument for register_post_type()
, so you can get rid of that line. 仅有几点观察:
register_post_type()
没有所谓的'type'
参数,因此您可以摆脱这一行。 Second, 'with_front' => false
is telling WordPress that the URL structure should be /training/training-page/
. 其次,
'with_front' => false
告诉WordPress URL结构应为/training/training-page/
。 /wordpress/
in this isntance is the 'front' part you're telling it to leave off. /wordpress/
在这种情况下是您要告诉它的“前”部分。 Additionally, you don't need to add 'taxonomies' for the post_type, but you do need to register the post type before you register the taxonomy. 此外,您无需为post_type添加“分类法”,但是在注册分类法之前,您确实需要注册帖子类型。 So try this:
所以试试这个:
<?php
add_action( 'init', 'tv_content_posttype' );
function tv_content_posttype() {
register_post_type( 'training',
array(
'labels' => array(
'name' => __( 'TV Training' ),
'singular_name' => __( 'TV Training' )
),
'public' => true,
'rewrite' => array(
'with_front' => true,
'slug' => 'training',
),
'hierarchical' => true,
'query_var' => true,
)
);
register_taxonomy('content',
'training',
array(
'hierarchical' => true,
'label' => 'Content Index',
'query_var' => true,
'rewrite' => true
)
);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.