Do post_names have to be unique?

Slugs need to be unique-ish.

The function that determines what a slug will be is called, appropriately enough, wp_unique_post_slug.

  • Attachment slugs need to be unique across the whole set of slugs. Meaning that they cannot be shared with anybody, anywhere.
  • Page slugs (or any hierarchical post type) needs to be unique within that specific post type (and also not shared with any attachments). There’s a few other restrictions, like you cannot use “embed” or “feed” or any other keywords WordPress already uses in URLs. So, you cannot have two pages named “about” for example, even if they are on different parts of the tree and thus have different parents.
  • Posts slugs must be unique across all posts (and also not shared with attachments). Same keyword restrictions.