WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#35502 closed defect (bug) (worksforme)

post_name does not get added when using post_status other than publish

Reported by: Jossnaz Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.4.1
Component: Posts, Post Types Keywords:
Focuses: Cc:

Description

the beautiful documentation on https://codex.wordpress.org/Function_Reference/wp_insert_post lacks elementary information.
post_name does NOT get inserted when using a normal editor user (not wp-admin) and using this code

<?php
 $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);

this is NOT stated in the docs.

This works:

<?php

$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);

now how does wordpress itself store the slug before it is published? obviously, not in post_name.

If you feel good, feel free to answer on
http://wordpress.stackexchange.com/questions/214810/post-name-is-not-stored-until-post-is-published-where-should-i-store-my-slug

as I am not the only one wondering about this defect.

Change History (2)

#1 @Jossnaz
6 years ago

  • Resolution set to worksforme
  • Status changed from new to closed

I think I figured out it was a missing>

publish_posts or edit_published_posts rule that you can set in the User Role Editor

#2 @swissspidy
6 years ago

  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.