Can we have a post without a slug?

I know this is really old question, but today I was dealing with something similar, and I have found a solution – if wp_unique_post_slug() calling is performance bottleneck, and post_name value is not important, then set post_name manualy to some random value.

My wp_insert_post post action was taking too long lately (20-30s). It saves custom post type order not visible to visitors, with post_title = "Order" (post title does not matter). That resulted in thousands of posts with title “Order”, and WP was automatically generating post names (post_name) as “order-1”, “order-2”, “order-3”, … “order-6152” …

And with every wp_insert_post WP searched for free post name starting from “order” and incrementing suffixed number – and every step was one DB query. So in my case WP did more than 6,000 DB queries before inserting one post to database.

Setting random post_name in wp_insert_post() call disables wp_unique_post_slug() call.

Leave a Comment