Opened 9 years ago
Closed 9 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 | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Posts, Post Types | Version: | 4.9 |
| Severity: | normal | Keywords: | |
| Cc: | Focuses: |
Description
here is the example snippet
<?php $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 www.example.com/songs/parent-slug/child-slug
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 www.example.com/?post_type=songs&;p=1234
Change History (1)
Note:
See TracTickets
for help on using tickets.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
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.