#16283 closed enhancement (wontfix)
post_exists() enhancement - don't include revisions
Reported by: | durin | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 2.0 |
Component: | Administration | Keywords: | |
Focuses: | Cc: |
Description
The current post_exists() function to me has a major downside. By default all it does it search for title, content and/or date in the wp_posts table.
The problem with this is that it includes revisions. So for example if you have a post with title "ABC" but then later change it to "DEF", post_exists("ABC") will still return true with the post ID of the revision.
I would suggest either:
a) Adding post_status not equal "inherit" as a default to the function.
b) Adding a 4th parameter which allows you to pass the post_status value in.
I would be happy to code this if anyone has any feedback on what would be the best approach.
Attachments (1)
Change History (11)
#2
@
14 years ago
- Keywords dev-feedback added; post_exists removed
- Summary changed from post_exists() enhacement - don't include revisions to post_exists() enhancement - don't include revisions
The most common use case for post_exists
is, I'm guessing, to avoid title/content conflicts between published posts. On this basis I think the default behaviour should be to ignore old revisions, i.e., post_status != 'revision'
, and maybe add an argument to allow override.
#3
follow-up:
↓ 4
@
14 years ago
So how do we handle when someone decides to revert to the revision with ABC as a title?
Much like not re-using slugs while posts are in the trash we need to be careful here.
#4
in reply to:
↑ 3
@
14 years ago
Replying to westi:
So how do we handle when someone decides to revert to the revision with ABC as a title?
I don't see why this would be an issue? Titles don't have to be unique like slugs. It's no different from someone creating a new post which has a title identical to some other old post - works fine and wp_insert_post
will handle the slugs.
#8
@
11 years ago
- Keywords dev-feedback needs-patch removed
- Resolution set to wontfix
- Status changed from new to closed
- Version changed from 3.1 to 2.0
post_exists
is not used anywhere in core. The common use case is avoiding duplicate when importing content. If you import a post then make slight changes when your importer runs again, you need to check revisions because if not, you would be importing the same post 2 times because the original has changed.
#9
follow-up:
↓ 10
@
11 years ago
Shouldn't we reopen this ticket or create a new one to deprecate it then?
#10
in reply to:
↑ 9
@
11 years ago
- Milestone Awaiting Review deleted
Replying to markoheijnen:
Shouldn't we reopen this ticket or create a new one to deprecate it then?
Doesn't seem like it, at least the deprecating part; importer plugin uses it, as c3mdigital noted.
If true then +1 to addressing this.