admin管理员组文章数量:1125080
I'm seeking assistance with a custom permalink issue I'm facing on my WordPress website. I've been trying to implement custom permalinks for posts belonging to specific categories, namely "Special Interview" and "Top Consultant," but haven't had much success. Here's what I've attempted so far:
function custom_category_permalink($permalink, $post, $leavename) {
// Get the post's categories
$categories = get_the_category($post->ID);
if ($categories) {
foreach ($categories as $category) {
// Check if the post is in "Special Interview" or "Top Consultant" category
if ($category->slug === 'special-interview' || $category->slug === 'top-consultant') {
// Append "magazine" to the permalink
$permalink = trailingslashit(get_site_url()) . 'magazine/' . $post->post_name . '/';
break; // Stop loop once the condition is met
}
}
}
return $permalink;
}
add_filter('post_link', 'custom_category_permalink', 10, 3);
add_filter('post_type_link', 'custom_category_permalink', 10, 3);
I updated this code on my functions.php and it did work for a while but few minutes later, the links result in a "Page Not Found" error. I did clear all my cache, did a Permalink Refresh but it did not work. I wonder what is the issue.
Your help will be greatly appreciated! Thank you!
本文标签: Custom permalink structure for posts in specific category not working
版权声明:本文标题:Custom permalink structure for posts in specific category not working 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736630517a1945767.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论