admin管理员组文章数量:1130349
We have a multi-author WordPress site where different authors need the ability to use the same slug (post_name). Right now WordPress will append a -2 to the slug but how can we prevent WordPress from appending dashes and keeping the slug the same? Note that our permalinks will still be unique even if the slug is the same as we use the author's username in the permalink as illustrated below:
Current Implementation:
example/author1/post-slug
example/author2/post-slug-2
Desired Implementation:
example/author1/post-slug
example/author2/post-slug
Please advise on how we can achieve the desired implementation. Thank you.
We have a multi-author WordPress site where different authors need the ability to use the same slug (post_name). Right now WordPress will append a -2 to the slug but how can we prevent WordPress from appending dashes and keeping the slug the same? Note that our permalinks will still be unique even if the slug is the same as we use the author's username in the permalink as illustrated below:
Current Implementation:
example/author1/post-slug
example/author2/post-slug-2
Desired Implementation:
example/author1/post-slug
example/author2/post-slug
Please advise on how we can achieve the desired implementation. Thank you.
Share Improve this question asked Oct 31, 2018 at 20:09 HBCondoHBCondo 1537 bronze badges 5 |1 Answer
Reset to default 0I ended up adding this code that makes the default post type hierarchical and populating the wp_posts.post_parent field with the author ID. The combination of these two has achieved the desired implementation of having the same slug across multiple authors.
// Set post type "post" to be hierarchical
$wp_post_types['post']->hierarchical = 1;
Source: https://stackoverflow/questions/10750931/wordpress-how-to-add-hierarchy-to-posts
We have a multi-author WordPress site where different authors need the ability to use the same slug (post_name). Right now WordPress will append a -2 to the slug but how can we prevent WordPress from appending dashes and keeping the slug the same? Note that our permalinks will still be unique even if the slug is the same as we use the author's username in the permalink as illustrated below:
Current Implementation:
example/author1/post-slug
example/author2/post-slug-2
Desired Implementation:
example/author1/post-slug
example/author2/post-slug
Please advise on how we can achieve the desired implementation. Thank you.
We have a multi-author WordPress site where different authors need the ability to use the same slug (post_name). Right now WordPress will append a -2 to the slug but how can we prevent WordPress from appending dashes and keeping the slug the same? Note that our permalinks will still be unique even if the slug is the same as we use the author's username in the permalink as illustrated below:
Current Implementation:
example/author1/post-slug
example/author2/post-slug-2
Desired Implementation:
example/author1/post-slug
example/author2/post-slug
Please advise on how we can achieve the desired implementation. Thank you.
Share Improve this question asked Oct 31, 2018 at 20:09 HBCondoHBCondo 1537 bronze badges 5- It sounds like you're using a non-hierarchical post type. As long as you are using Pages, or a CPT such as perhaps "author" that is hierarchical, WP will allow duplicate child slugs as long as the top-level pages (author1, author2) have unique slugs. – WebElaine Commented Oct 31, 2018 at 21:18
- Thank you for your reply. This is indeed for non-hierarchical post types but these are for standard WordPress posts (not custom), not pages. – HBCondo Commented Oct 31, 2018 at 22:52
- That's your problem - you cannot have duplicate slugs in a non-hierarchical post type like Post. WP looks at the slug first to determine what content to display, and if there's more than one - and they don't have a parent - it would not know which to display. To get URLs like this you will have to use a hierarchical post type. – WebElaine Commented Nov 1, 2018 at 14:31
-
I'd say assign a custom field to the posts, maybe name it
author_post_slugand give it the same value (e.g. post_slug), and filter the URL requests viaparse_request, or create custom rewrite rules for those URLs. – Sally CJ Commented Nov 1, 2018 at 19:42 - Thank you for these suggestions. We already imported over 200K posts using the standard post type. We may just specify the author id in the post_parent field so we can achieve having the same post_name for different authors. Thoughts on this approach? Adding custom fields for our large post count may not be feasible and rewriting doesn't really solve the problem of WP appending -2 to post_name. – HBCondo Commented Nov 7, 2018 at 0:58
1 Answer
Reset to default 0I ended up adding this code that makes the default post type hierarchical and populating the wp_posts.post_parent field with the author ID. The combination of these two has achieved the desired implementation of having the same slug across multiple authors.
// Set post type "post" to be hierarchical
$wp_post_types['post']->hierarchical = 1;
Source: https://stackoverflow/questions/10750931/wordpress-how-to-add-hierarchy-to-posts
本文标签: permalinksHow to allow different authors to use same post slug
版权声明:本文标题:permalinks - How to allow different authors to use same post slug? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749196315a2331037.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


author_post_slugand give it the same value (e.g. post_slug), and filter the URL requests viaparse_request, or create custom rewrite rules for those URLs. – Sally CJ Commented Nov 1, 2018 at 19:42