Skip to content

Fix incorrect global post object when field is fields => 'id=>parent for WP_Query.#7985

Closed
Juzar10 wants to merge 9 commits intoWordPress:trunkfrom
Juzar10:fix/incorrect-fields-id-parent-global-post-set
Closed

Fix incorrect global post object when field is fields => 'id=>parent for WP_Query.#7985
Juzar10 wants to merge 9 commits intoWordPress:trunkfrom
Juzar10:fix/incorrect-fields-id-parent-global-post-set

Conversation

@Juzar10
Copy link

@Juzar10 Juzar10 commented Dec 10, 2024

The next_post function assumes a WP_Post object, which isn't always the case. When a standard object with ID and parent is provided, setup_postdata creates an empty WP_Post object with just the ID.

This PR resolves the issue by passing only the post ID from next_post when the object is not a WP_Post.

Trac ticket: https://core.trac.wordpress.org/ticket/56992


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@github-actions
Copy link

github-actions bot commented Dec 10, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props juzar, peterwilsoncc, joemcgill, sirlouen.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions
Copy link

Test using WordPress Playground

The 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

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Copy link
Member

@joemcgill joemcgill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than returning a possible int value when the current post isn't a WP_Post object, would it be better to hydrate a WP_Post object from the ID and return that instead?

@Juzar10
Copy link
Author

Juzar10 commented Feb 5, 2025

@joemcgill, I agree with you, that would be more consistent. I have updated the logic to return WP_Post object.

Copy link
Contributor

@peterwilsoncc peterwilsoncc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a suggestion inline to expand the tests to include calls to ::next_post and to make sure requesting only the IDs returns the expected data.

Let me know what you think.

Juzar10 and others added 2 commits February 6, 2025 20:47
Co-authored-by: Peter Wilson <519727+peterwilsoncc@users.noreply.github.com>
Copy link
Contributor

@peterwilsoncc peterwilsoncc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Juzar10, this change looks good to me.

I took the liberty of merging trunk in to your branch as some significant changes were committed to WP_Query in the last 24 hours so I wanted to make sure there weren't any conflicts.

@Juzar10
Copy link
Author

Juzar10 commented Feb 7, 2025

thanks, @peterwilsoncc.

Copy link
Member

@joemcgill joemcgill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me. Thanks for the updates!

@SirLouen
Copy link
Member

@joemcgill just to make sure, have you read the trac info, before approving these changes?

@joemcgill
Copy link
Member

joemcgill commented Feb 27, 2025

@SirLouen thanks for the ping. I approved the PR before the ongoing conversation the Trac ticket and am happy to wait for you and @peterwilsoncc to refine the approach.

@github-actions
Copy link

github-actions bot commented Mar 3, 2025

A commit was made that fixes the Trac ticket referenced in the description of this pull request.

SVN changeset: 59919
GitHub commit: e6fa3b9

This PR will be closed, but please confirm the accuracy of this and reopen if there is more work to be done.

@github-actions github-actions bot closed this Mar 3, 2025
@peterwilsoncc
Copy link
Contributor

This was the basis for the follow up PR #8418 which ended up being merged, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants