0

I'm using function get_posts to retrieve a set of post objects that are my custom post type (CPT). I am counting on being able to programmatically flip these posts between status "publish", "pending" and "draft".

Before I go through the trouble of detecting and "fixing" potential duplicates -- is it even something I have to worry about? Is there any scenario where the same CPT post_name can reside in the wp_posts table in more than one (row) of differing post_status: publish, pending or draft?

(edit) After some experimentation I found that when inserting a post of status "pending", it ignores the post_name parameter - so that ends up being blank in the database. And yes, it will allow many rows in the wp_posts table with the same post_name of '' (blank). I'm sure there's a good reason for this but it is not what I expected that's for sure.

0

No, multiple posts with the same CPT and post name (slug) are not possible. Someone can work hard and ruin the DB by writing into it some illegal values, but that should not be something you think of when writing your code.

Posts in their initial state are not true posts, they are just place holders, therefor while your observation is valid, it is not really relevant for usual usage pattern of wordpress API, unless once again your aim is to break things.

  • Thanks, Mark. Not looking to break anything ;-) My plugin is so narrowly focused on one business process, too much to describe here - but I was depending on being able to manage workflow by toggling CPT status. I think I'll look for another field to use, or maybe register custom post status values, instead. – C C Dec 4 '15 at 15:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.