Make WordPress Core

Opened 5 days ago

#61969 new defect (bug)

Post guid for custom post type being modified

Reported by: peter8nss's profile peter8nss Owned by:
Milestone: Awaiting Review Priority: normal
Severity: minor Version: 6.6.1
Component: Posts, Post Types Keywords:
Focuses: Cc:

Description

I understand that a post's guid should generally be invariant, i.e. once set it should not normally be changed. WordPress core seems to violate this for custom post types.

When creating a post for a custom post type the guid created is (now) of the form:

<domain>/?post_type=<custom post type>&=p=<post id>

When that post is first updated the guid gets changed to

<domain>/?post_type=<custom post type>&#038;p=<post id>

I think this is happening because of the filter added on post_guid calling esc_url (see wp-includes/default-filters.php) which is called when updating the post but not when originally creating it.

Note the creating logic sets guid using get_permalink which in turn calls get_post_permalink and does not include any use of esc_url.

You can recreate the problem, providing you have a custom post type available, by the following WP CLI commands:

wp post create --post_title='Initial create' --post_type=<custom post type>

guid will be set as described above

wp post update <post id> --post_title='Updated title'

guid will be revised as described above
And you can use "wp post get <post id>" to see the different guid values

Naively, I would suggest two ways of fixing this:
1) Remove the default filter on post_guid that calls esc_url
2) Wrap the call to get_permalink in wp_insert_post in a call to esc_url

Change History (0)

Note: See TracTickets for help on using tickets.