post_name is not stored until post is published... where should I store my slug until it goes live then?

important try as normal contributor user, not as admin

see here I actually have it reproduced. Seems like a bug to me but whatever. I want users to choose their slug. Well, as you cannot store post_name in pending posts, where should I store it? where does wordpress store the slug the user chooses while it is still draft / pending?

EDIT

my code, this works as it is publish status:

  $post_information = array(
    'post_title' = 'Your title',
  'post_content' = 'blabla',
  'post_type' = 'post',
  'post_author' = wp_get_current_user()-ID,
  'post_status' = 'publish',
  'post_name' = "somerandomstuffthatisunique222"
);
$new_id = wp_insert_post( $post_information);

$postl = get_post($new_id);

this does not work

       $post_information = array(
    'post_title' = 'Your title',
  'post_content' = 'blabla',
  'post_type' = 'post',
  'post_author' = wp_get_current_user()-ID,
  'post_status' = 'pending',
  'post_name' = "somerandomstuffthatisunique2223434343434"
);
$new_id = wp_insert_post( $post_information);

in case 2, post_name is empty string after insert.

the author doesn't matter

Topic post-meta slug permalinks posts Wordpress

Category Web


When you use the graphical interface, post_name is stored in the wp_posts table even for draft posts as soon as you modify the default value.

I tried your code (case 2) and I actually see the new entry in the database, with the correct post_name. Perhaps your check to post_name is not correct ?

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.