Repository navigation
Conversation
When the queried object ID doesn't resolve to a post, `get_post()` returns null and the post type lookup warns. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
| $post = get_post( get_queried_object_id() ); | ||
| if ( $post ) { | ||
| $post_id = $post->ID; | ||
| } |
There was a problem hiding this comment.
What about this?
| $post = get_post( get_queried_object_id() ); | |
| if ( $post ) { | |
| $post_id = $post->ID; | |
| } | |
| $queried_object = get_queried_object(); | |
| if ( $queried_object instanceof WP_Post ) { | |
| $post = $queried_object; | |
| $post_id = $queried_object->ID; | |
| } |
There was a problem hiding this comment.
Thanks, applied in c5d8fde. I also added tests for the query context, including one where the queried object is not a post (it fails with the original warning on trunk).
In the `query` context, use the queried object directly when it is a post instead of looking the post up again by ID. Adds tests for the `query` context, including a queried object that is not a post. See #66348. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
|
heya @westonruter 👋 what is remaining for us to push this through the finish line? |
Trac ticket: https://core.trac.wordpress.org/ticket/66348
In
wp_get_shortlink()with thequerycontext,$post_idcomes fromget_queried_object_id()while$postcomes fromget_post(). When the ID is non-zero butget_post()returns null,wp_shortlink_header()warns:Seen on WordPress.org from a scanner POSTing many junk parameters to a handbook landing page. This derives
$post_idfrom the resolved post, matching thepostcontext branch.🤖 Generated with Claude Code