• Hello, I’m making a plugin that will register a custom post type and the plugin will also regularly create, or update, posts within that custom post type.

    It will integrate with a 3rd party service, via restapi.

    When the plugin receives incoming data from the 3rd party it will contain a unique id already, which if its pertaining to a previously created post in my custom post type, the unique ID will remain the same as it did on its first incoming data. I want to use that unique ID to look up previously created posts… to determine if i need to create a new post, or update the existing one.

    When I Google this kind of thing I am seeing “don’t change post IDs” etc, and I get that.

    But given the context I’ve provided so far, would it be okay if I used the 3rd party’s unique ID and set the post id to their unique ID? They will never ever match another post in my wordpress install, they are pretty long numbers, and I may even include a prefix character to further prevent any kind of duplicate post ID issue..

    I want to do this because I believe the lookup by post_id is very high performing vs. using meta tables etc.

    I appreciate anyone’s time commenting on this.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    “would it be okay if I used the 3rd party’s unique ID and set the post id to their unique ID? ” No, overriding the server-selected ID will most likely break things. Add a post_meta for your external ID when you create the post and use it to look up the post when dealing with the external ID.

    Thread Starter miketopher

    (@miketopher)

    Thanks for the reply.

    I don’t wish to override, I wish to dictate the post ID initially.

    Could you elaborate as to why it’s dangerous? Because this is a custom plugin I’m making with a custom post type registered via my plugin, I feel like the dangers of overriding are probably not rational in my specific scenario.

    Any elaboration would be highly appreciated, if the dangers are things which I could rule out as being non-issues in my scenario, I would love to consider more thoroughly.

    Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    Primary key IDs are managed by the database server. Best to keep what you manage separate from what’s auto-managed.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Creating a custom post type & specifying its POST IDs?’ is closed to new replies.