If you use wp_insert_post
, it should calculate a unique post slug for you. If you don’t use wp_insert_post
, try using wp_unique_post_slug
. If neither of those are working for you, you could simple try appending -page
or to the new page’s post_name
(slug) before inserting it.
WordPress does its uniqueness check on post slugs at application level — it doesn’t look like there’s a unique index on wp_posts.post_name
. So, for instance, if you’re inside a transaction where you’re creating two posts simultaneously, the uniqueness checks would fail. It’s also possible that you could create some sort of race condition where the two posts are being inserted at the same time and a uniqueness check on both slugs would fail.
Related Posts:
- How to prevent post_name from incrementing in wp_insert_post?
- How to get a taxonomy term name by the slug?
- How to set post slug when using wp_insert_post();?
- Is there a maximum slug length?
- How to check if a slug exists?
- Can I use a number for a post/page slug?
- Force post slug to be auto generated from title on save
- How to rewrite slug of custom post type archive page
- How to get full slug, including all parent pages
- Remove Slug from Custom Post Type
- Add warning to edit slug/permalink button on editor screen.
- How to remove certain words from url slug
- How to generate slugs?
- {Check Theme Plugin} text domain does not match the theme’s slug
- Possible to create a new post and have the Title and Slug automatically use the post’s ID?
- Display page over category archive
- Convert post name into post ID
- WP appending -2 to the end of my slug. Where are the originals stored so I can delete them?
- Yoast SEO breadcrumbs: how to create a filter that uses the url slug for breadcrumb titles
- Function to list all post slugs for every post in my WP database?
- generate unique slug while inserting post
- Add parent template name to body class filter when visiting subpage or single post
- How I Can Use The Get Value as A Slug
- Set taxonomy slug as taxonomy title
- custom slug always ends in “-2”
- Show all wp_get_post_terms slugs
- Hook on slug generator
- How can I automatically set a post slug based on the post title during post publish?
- Do post_names have to be unique?
- slug: should I use latin characters only?
- How to manage same slug posts suffix method?
- Make wp_list_pages print slugs instead of titles
- Stripping unicode characters out of slug
- Remove slugs of old and unused custom post type
- What function removes apostrophes when making a slug?
- WordPress not adding -2 to slugs when saving post as draft
- wp_insert_post – How do I prevent incremental numbers on child pages?
- Memberpress custom fields – filtering content
- Duplicate category slugs from pages and posts
- How to show “slug” in admin column?
- Change post slug but keep old one
- Why does post-slug not get saved for drafts?
- Remove custom post slug and add category to custom post type
- WordPress Reserved Terms, any workaround?
- Slug Taken, Cant Find Which Page
- How to get a page slug in WordPress?
- A way to export slug as meta tag
- Adding language based URL structure
- Display Terms Comma separated and Hyperlinked
- Is it possible to create slug on homepage and how?
- what to do when a Theme uses a custom post type slug that conflicts with a plugin?
- Wrong slug on blog page
- Can’t remove slug in url
- Set a custom post type’s title and slug to match the current date
- One Page or Post, n Slugs
- add slug of child(ren) to li using wp_list_pages
- Category Slugs = 404s?
- How can I get wordpress slug without certain phrase? [closed]
- Check for the existence of term slug
- How to ignore GET parameter that’s the same as a CPT slug?
- Make user’s first and last name as user slug
- permalink not showing correctly using wp_insert_post and post_name
- Default post category overruling %category% setting for posts URL
- 404 errors problem with multilangual permalink pages
- Show post by slug sanitize_title
- Category Name and Slug field need to be the same otherwise it breaks category pages
- Get all terms/slugs – used, not used & in hierarchical order
- Bulk-change Post slugs which have a suffix
- Generate slug and meta data if meta field is empty
- How to print partial URL after #? [closed]
- How to Disable UNICODE slug?
- list child pages as slug
- Is this the correct way to add post-slug input field?
- can’t change page slug
- How to put title slug into content when create a new post?
- WordPress v3.1 Has Character Encoding Issue With Title/Permalink?
- Is there any point to using wp_unique_post_slug?
- Ultimate get current page’s slug function
- How To Change Username Slug
- How can I make “sanitize_title” affect only one taxonomy?
- How to create extra SUB ARCHIVE for each page?
- Slug is already taken – how do I find the original item
- Duplicate Slugs on multilingual site (with Polylang)
- Why don’t WordPress post slugs allow accents?
- Endless loop with wp_insert_post and wp_update_post
- How to get Plugin Slugs?
- Changing search slug from + to – (hyphen)
- How to query for pages/post depending on slug?
- Can slugs from posts and custom post types conflict?
- Custom Post Type archive-{post-type}.php not working
- Custom post type single page (single-{CPT-name}) 404 when slug includes hyphens
- page-slug.php not working but only for specific slug
- tax_input in wp_insert_post partly not working
- add_rewrite_rule – Page Slug from “/foo-bar/” to “/foo/bar/”
- wp_insert_post Only creates draft
- get_term_by with a variable
- Post meta data not showing in frontend, until hitting ‘update’ button
- How to change parent permalink?
- Post content not showing some content
- Custom Post Type Slug / Page Slug Conflict – Prevent use of reserved slug on page save?