WordPress自定义帖子类型更改为固定链接显示404
问题描述:
我已经创建了自定义帖子类型post_event_type并且在注册时已将rewrite设置为true。WordPress自定义帖子类型更改为固定链接显示404
在这个岗位类型,有EVENT_CATEGORY与改写的分类设置为在类别真正
然后将URL解析这个帖子的网址/ post_event_type/postname
有三种类别下分类标准event_Category如电影院,舞蹈,音乐。
我想要的网址解析到的页面作为此类网址/舞蹈/ postname所以“舞”将是分类类别和文章名称将驻留在此类别
下后如果我改变了注册公告键入重写为“事件”,他们将全部解析为URL/events/postname
然后我尝试了下面的代码尝试将它们分离出来。这些网址以我想要的方式工作,然而他们然后转到404页面。
add_filter('rewrite_rules_array', 'mmp_rewrite_rules');
function mmp_rewrite_rules($rules) {
$newRules = array();
$newRules['events/(.+)/(.+)/(.+)/(.+)/?$'] = 'index.php?vc_guide_creator=$matches[4]';
$newRules['events/(.+)/?$'] = 'index.php?event_Category=$matches[1]';
return array_merge($newRules, $rules);
}
global $wp_rewrite;
$structure = '/%events%/';
$wp_rewrite->add_rewrite_tag("%events%", '([^/]+)', "post_event_type=");
$wp_rewrite->add_permastruct('post_event_type', $structure, false);
function filter_post_type_link($link, $post)
{
if ($post->post_type != 'post_event_type')
return $link;
if ($cats = get_the_terms($post->ID, 'event_Category')){
$link = str_replace('post_event_type', array_pop($cats)->slug, $link);
}
return $link;
}
add_filter('post_type_link', 'filter_post_type_link', 10, 2);
任何人都可以帮忙吗?
答
您是否尝试过更新您的固定链接。
进入设置 - >固定链接,点击底部的保存更改按钮而不更改任何设置,这将只更新永久链接表。
任何人都可以帮助这个吗? – Techballs