admin管理员组

文章数量:1122846

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

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

Share Improve this question edited May 23, 2017 at 12:40 CommunityBot 1 asked Jan 17, 2016 at 20:51 ToskanToskan 5242 gold badges8 silver badges23 bronze badges 1
  • please post your code. anyway that code does not set an author which might or might not be the issue.there – Mark Kaplun Commented Jan 17, 2016 at 21:12
Add a comment  | 

1 Answer 1

Reset to default 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 ?

本文标签: