WordPress.org

Make WordPress Core

Opened 11 years ago

Closed 10 years ago

#98 closed defect (bug) (fixed)

Multiple posts with same post-slug

Reported by: 2fargon Owned by: matt
Milestone: Priority: normal
Severity: minor Version: 1.2
Component: Administration Keywords:
Focuses: Cc:

Description

WordPress allows me to publish multiple (totally different) posts with the same post-slug.
This leads to a contention between the posts for the URL, when Permalinks are used.

Attachments (3)

0000098-post_names_patch_102.txt (1.4 KB) - added by 2fargon 10 years ago.
0000098-post_names_patch-post.php (925 bytes) - added by 2fargon 10 years ago.
0000098-post_names_patch-post.txt (925 bytes) - added by 2fargon 10 years ago.

Download all attachments as: .zip

Change History (11)

comment:2 @majelbstoat11 years ago

Patch submitted for WP Patch Day :D

File attached (as .txt file this time!)

Sorry, I can't provide a diff because I knocked this up in an internet cafe ;D The file itself should be pretty self explanatory though...

I chose option b) - automatically creating a secondary name. I don't think there's any point in bothering the user with this kind of thing. Plus anything they entered would have to be re-sanitised and checked... It's a whole lot quicker to just do it 'magically' :D

Tested and working on my own WP installation, and I've updated it to use $wpdb->posts instead of $tableposts as per the latest CVS, so there should be no problems.

Contact address in the text file if there are any problems / comments.

comment:3 @anonymousbugger11 years ago

But surely you want to be able to post multiple posts with the same slug, so long as they're on different days (and thus get a different permalink under the default settings) why should it matter?

comment:4 @ringmaster11 years ago

Because I don't want to use dates in the permalinks at all. :)

comment:5 @majelbstoat11 years ago

Actually, there is a slight problem with version 1.01 of the code I submitted. At the moment, the name is being tested even when it is a draft. Seeing as you may or may not publish a draft, it doesn't make sense to alter the post_name until it is published. Version 2 corrects this, but requires that the code be in the 'post' section and the 'editpost' section. As identical code is called twice, maybe it makes sense to have this as a separate function?

ie: $post_name = get_unique_postname($post_name);

Uploading an attachment with the alterations now... Sorry no diff again :( (But you should get the idea).

comment:6 @majelbstoat11 years ago

Another minor change, not in the code this time, but of the position where the code should be inserted. Full explanation in http://www.jamietalbot.com/wp-hacks/post-slug-patch-103.phps but rough explanation is that problems would occur if a post was continually edited and saved but not published. Moving the code further down the file fixes it.

This also highlights what I consider to be a significant UI bug - the existence of a "Draft", "Private" and "Publish" option group which is then overridden by which button the user clicks. It was because of this that I didn't notice the bug until now, as I was clicking Draft and then pushing Publish by mistake. For half of the file, post-status is treated as 'draft' until a test half way down where it changes to 'publish'. Not only is it redundant, it is also confusing (to me at least) both as a programmer and blogger.

This seperate issue has previously been raised as bug 0000124, but seems to have got a little lost...

edited on: 08-02-04 15:19

edited on: 08-04-04 10:55

edited on: 08-04-04 10:56

comment:7 @majelbstoat11 years ago

Another small change, this time so the post doesn't match against itself. Bit more rigorously tested this time, so there shouldn't be any more...

http://www.jamietalbot.com/wp-hacks/post-slug-patch-104.phps

comment:8 @2fargon11 years ago

This works for me, please close.

comment:9 @2fargon11 years ago

  • Patch set to Yes

comment:10 @matt10 years ago

  • fixed_in_version set to 1.5
  • Owner changed from anonymous to matt
  • Resolution changed from 10 to 20
  • Status changed from new to closed

TODO: Use WP_Query to check against permalink structure.

Note: See TracTickets for help on using tickets.