Make WordPress Core

Opened 7 years ago

Closed 7 years ago

#42727 closed defect (bug) (invalid)

wp_insert_post() for custom post types generates wrong URL in the field wp_posts->guid

Reported by: antonv's profile antonv Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.9
Component: Posts, Post Types Keywords:
Focuses: Cc:


here is the example snippet

$newpost_args = array(
   "menu_order" => $new_menu_order,
   "post_parent" => $post_parent_id,
   "post_status" => ( ('publish' == $post_status) && !current_user_can('publish_posts') ? 'pending' : $post_status ),
   "post_title" => $one_new_post_name,
   "post_type" => "songs",
    $new_post_id = wp_insert_post($newpost_args);

the wp_posts->guid is now set to

All good and well till you change the slug in the Edit or Quick Edit and the post is no longer reachable and returns 404!

If I create the same child post in Edit
then wp_posts->guid is set to;p=1234

Change History (1)

#1 @dd32
7 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

Hi @antonv and welcome to Trac.

The GUID field should not be treated as a URL to a entity, although currently the guid field is normally a short-url, there's no expectation that it's a resolvable URL to the item.

The GIUD field could be set as a real UUID or the md5 of the post and still be valid.

Anytime you need to access the URL to a post type, you should be using get_permalink().

I'm going to close this as invalid, as although it's being set to different defaults based on where the post is being made from, there shouldn't be any expectation from a code perspective that it's a real URL.

Note: See TracTickets for help on using tickets.