自定义文章类型URL重定向错了
问题描述:
我有一些Wordpress CPT。他们正确的URL应该是/ wordpress/training/training-page /,这就是我在管理管理页面看到的URL,但是当我点击链接时,我最终得到的URL是/ wordpress/blog/2010/05/21 /培训页/。自定义文章类型URL重定向错了
我停用了我的插件没有成功。有谁知道如何保持正确的URL完好?
这里是我的代码:
<?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'),
)
);
}
答
就在几个意见:有一个'type'
论据register_post_type()
没有这样的事情,这样你就可以摆脱线。其次,'with_front' => false
告诉WordPress,URL结构应该是/training/training-page/
。 /wordpress/
在这个isntance是你告诉它离开的'前'部分。此外,您不需要为post_type添加“分类法”,但是在注册分类标准之前您需要注册帖子类型。所以试试这个:
<?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
)
);
}