The -2 is added when you add a post with a slug that is not unique. Simply make your slugs unique and if needed use a redirect for old URL’s.
That is the correct way to handle this.
That’s correct but that is not the issue.
Using a permalink structure of only /%postname%/
, it is not possible to create a post without a title which uses a slug without -2
. That’s the issue I’m trying to solve.
In other words, because I choose to use only /%postname%/
, WordPress is forcing un-titled post slugs to default to the Post ID and appends -2
on every published post that does not have a title as the auto-generated slug.
My only alternative, which I’m trying to avoid, is to manually create a slug for posts that do not have titles.
-
This reply was modified 4 years, 10 months ago by
micasuh. Reason: clarification
-
This reply was modified 4 years, 10 months ago by
micasuh.
@micasuh,
I took some time today to further review this issue. I was able to replicate this issue on multiple sites running varying themes and plugins and even a default site install (latest WP version, default theme, no plugins).
I did find that whenever I use the permalink structure of /%postname%/
, created a post, but did not add a title, the slug was in fact appended with a -2.
I believe this is a bug. Please report it and reference this post, providing additional information as needed.
https://make.wordpress.org/core/handbook/testing/reporting-bugs/
Thank you for the feedback! I have reported this as a bug:
https://core.trac.wordpress.org/ticket/43593
You are welcome. My thoughts based on the lead developers response at the trac is that if a post title is now not given that it defaults back to postid. Why it adds the -2 then is unclear sans i step thru every line of PHP to figure that out.
The answer is way down in ticket 5305.
I believe this post is where the chain of devs stated this is a feature and not a bug.
I don’t know how to state my case on the ticket I created because I disagree with the outcome of what they’re trying to do specifically for /%postname%/
since it’s designed to fix a problem with date based permalinks.
I also don’t understand @dd32’s comment about WordPress not supporting numeric based slugs when it seems clear that /%post_id%/
is this support as a permalink?
His solution is to use wp_unique_post_slug but I’m not versed enough in PHP to know how to do this. Maybe someone reading this could help develop a plugin based around this function? Seems like it should be possible to do what I stated in the first post, which is to use the Post ID for titleless posts, checking with the wp_unique_post_slug
function to make sure it’s unique?
What am I missing?
-
This reply was modified 4 years, 10 months ago by
micasuh.
1. That trac ticket was started 10 years ago – please take the time to review them in considered detail.
2. When they write ‘not supported’, it means they will spend no more time on the issue for a very range of circumstances.
3. Specifically, I am unsure why they also are no referencing here, where another has noted the same behavior with no plugins and a default theme.
4. Often, these issues take time and may need a longer review. Often, in my experience, they can work them out, but full public disclosure will not be a part of this forum or trac,