admin管理员组文章数量:1431514
When i change the permalink of my CPT using filters it gives a 404. I clicked save in the permalinks settings and switched and saved, but there's still a 404. Is there some kind of hooking up i need to do with a rewrite to make this work?
function my_permalinks($permalink, $post, $leavename) {
$post_id = $post->ID;
if($post->post_type != 'model-list' || empty($permalink) || in_array($post->post_status, array('draft', 'pending', 'auto-draft')))
return $permalink;
$parent = $post->post_parent;
$parent_post = get_post( $parent );
$permalink = str_replace('model-list/', '', $permalink);
return $permalink;
}
add_filter('post_type_link', 'my_permalinks', 10, 3);
the url is looking correct, but it gives a 404
When i change the permalink of my CPT using filters it gives a 404. I clicked save in the permalinks settings and switched and saved, but there's still a 404. Is there some kind of hooking up i need to do with a rewrite to make this work?
function my_permalinks($permalink, $post, $leavename) {
$post_id = $post->ID;
if($post->post_type != 'model-list' || empty($permalink) || in_array($post->post_status, array('draft', 'pending', 'auto-draft')))
return $permalink;
$parent = $post->post_parent;
$parent_post = get_post( $parent );
$permalink = str_replace('model-list/', '', $permalink);
return $permalink;
}
add_filter('post_type_link', 'my_permalinks', 10, 3);
the url is looking correct, but it gives a 404
Share Improve this question asked Apr 21, 2019 at 8:09 Tintinabulator ZeaTintinabulator Zea 1298 bronze badges1 Answer
Reset to default 3post_type_link
is a filter that is applied to the URL for a post before it’s returned by get_post_permalink
.
So it doesn’t change any rewrite rules and the structure of permalinks is still the same.
So yeah - if you use it to change the structure of links, you have also to change the rewrite rules in such way, that the new link is matched and processed correctly.
本文标签: custom post typesposttypelink filter causes 404 on the CPT page it39s used on
版权声明:本文标题:custom post types - post_type_link filter causes 404 on the CPT page it's used on 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745569259a2663947.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论