skip to Main Content

A given post or page become a new record in the table wp_posts with a new ID every time a change is made to the post (or page).

Said that the ID cannot be used to identify a given post.

I could use the post_title but this may be edited.

Should I then use post_name?

I’m not sure what post_name represents in the WordPress logic.

2

Answers


  1. The ID is a unique number assigned to each post or page when it’s created. The ID never changes for a specific post, regardless of any edits or revisions made to it. It’s a reliable way to uniquely identify a post. However, as you noted, each revision also gets its own ID, which can be confusing if you’re looking at the database directly.

    Login or Signup to reply.
  2. In WordPress, each post is uniquely identified by a numeric identifier by the post ID.

    but you can create a custom meta field for a unique identification number in WordPress, you can use the add_post_meta() function.

    $unique_id = uniqid('custom_prefix_', true);
    
    // Add the unique ID as post meta
    add_post_meta($post_id, '_unique_id', $unique_id, true);
    

    uniqid('custom_prefix_', true) generates a unique ID based on the current timestamp and a more entropy value (using true as the second parameter). You can customize the prefix and the uniqueness requirements based on your needs

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search