PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Post ID being used twice, with different author, in post creation. MYSTERY.

  1. tristanowen
    Member

    I have a very strange situation that I cannot find any evidence of in other forums, or anywhere else online.

    I have a form that when submitted, creates a custom post, and registers a user (using the register user addon). There is then another form for signed in users, which is equivalent, except it does not register the user of course, and does not include the fields relevant to that. The form also adds a bunch of custom fields/post metadata to the custom post.

    This is the situation:

    User A filled registered on the site and created a custom post - the post title did not get captured correctly and thus was assigned the name 'untitled_1'. The post seemingly had the post ID of 4533 (I will explain why 'seemingly'. I can see all of this data, except for the post ID, in an audit trail plugin that shows such information.

    The next day, a returning user filled in the equivalent form for logged in users, and in this case coincidently the post title also was not captured correctly, and the post was also assigned a title of 'untitled_1'. Now it seems that this custom post was also assigned the ID of 4533 - which obviously should never happen, even if the original 4533 had been deleted, right?

    From the times n the audit trail, and the times of adjacent posts (4532, 4534, 4535 etc.), it looks as though post 4533 was created the first time by that first new user. There is also a post revision saved shortly after I reckon the original was created, and this revision is timestamped before the now current version of post 4533 was created - this is also obviously not supposed to be possible (a revision being dated prior to the original).

    The biggest issue now is that these posts are private, but because the same post ID was used on the second post, all of the custom field data from the first was associated with it, therefore pulling in custom field data from another user on the front end of the site.

    So the questions really are:

    Should Wordpress ever be able to create a post with an ID that has been used before?
    Since it seems that this did occur, how did it happen?
    Could it be as a result of the coincidentally same titles ('untitled_1')?
    Is there something about the way posts are created by gravity forms that allowed for this to happen?
    How can I protect against this in future?

    Any insight at all would be greatly appreciated!

    Posted 11 years ago on Friday March 1, 2013 | Permalink
  2. Why are the post titles not being captured correctly? It seems if that problem were resolved there would be less chance of the other problems occurring.

    Posted 11 years ago on Monday March 4, 2013 | Permalink
  3. tristanowen
    Member

    Well I think that is a javascript issue, and I did suspect it might be related. I also thought though, that Wordpress/Gravity Forms would not assign a post ID that had already been used, just because a post with the same name as one that exists already, is created. Surely Wordpress protects against that? Does Gravity forms assign a post ID by somehow looking at the post title, and if it finds one with the same, assigns the same ID? Is there room for this possibility?

    I am going to try and fix the 'Untitled' post naming issue, but I'm still interested to know why this would happen, and how to prevent it.

    Thanks for your help so far!

    Posted 11 years ago on Monday March 4, 2013 | Permalink
  4. Does Gravity forms assign a post ID by somehow looking at the post title, and if it finds one with the same, assigns the same ID?

    Not by default. You could be using custom code to update an existing post, rather than create a new post, but I don't think that's what's happening (you would have had to have added this yourself.)

    Post titles do not have to be unique. There is protection against the slug being duplicated (teh slug is created and if it already exists, a -1 is added, then -2, etc, until something unique is found.

    Also, the post ID in the database is a unique key. It would be interesting to see if you have multiple records in the wp_posts table. I don't think it can happen in a normal installation.

    Posted 11 years ago on Wednesday March 6, 2013 | Permalink