WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 8 months ago

Last modified 8 months ago

#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)

idea.txt (926 bytes) - added by piyushmishra 3 years ago.
txt of a supposed idea

Download all attachments as: .zip

Change History (11)

comment:1 mikeschinkel3 years ago

  • Cc mikeschinkel@… added

If true then +1 to addressing this.

comment:2 solarissmoke3 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.

comment:3 follow-up: westi3 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.

comment:4 in reply to: ↑ 3 solarissmoke3 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.

comment:5 mikeschinkel3 years ago

  • Cc mikeschinkel@… removed

piyushmishra3 years ago

txt of a supposed idea

comment:6 piyushmishra3 years ago

  • Cc piyushmishra added

comment:7 SergeyBiryukov3 years ago

  • Keywords needs-patch added

comment:8 c3mdigital8 months 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.

comment:9 follow-up: markoheijnen8 months ago

Shouldn't we reopen this ticket or create a new one to deprecate it then?

comment:10 in reply to: ↑ 9 helen8 months 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.

Note: See TracTickets for help on using tickets.