0

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

  • please post your code. anyway that code does not set an author which might or might not be the issue.there – Mark Kaplun Jan 17 '16 at 21:12
0

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 ?

| improve this answer | |
  • try it as not admin user, I will update the question. As super admin, it worked for me too, but not as , say, contributor with simple 'edit_posts' privileges – Toskan Jan 17 '16 at 21:44
  • well you beat me to it, I think it was the missing publish_posts or edit_published_posts rule that you can set in the User Role Editor using the "User Role Editor" plugin – Toskan Jan 17 '16 at 21:54
  • OK, so that was a user capabilities issue ? Is it solved now ? – Fabien Quatravaux Jan 18 '16 at 8:07

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.