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
author_post_slug
and 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