New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sticky Posts are not being handled anymore in 0.3.0 #786
Comments
@mwidmann ah, you know what, I think we set So now we have it here: https://github.com/wp-graphql/wp-graphql/blob/develop/src/Data/Connection/PostObjectConnectionResolver.php#L117 The latter is from your PR. . .the former is from the model-layer branch, prior to your PR. I think we might want to actually remove the former and stick with your PR. So that sticky posts will be respected for the first query, but not the subsequent 🤔 If you remove it from here does it bring back the behavior you expect? |
@mwidmann so, as far as how GraphQL loads data, it actually does a very similar thing to WP_Query. When you execute a WP_Query, it makes one initial query for just the IDs, then it looks to see if those IDs are in the cache or not. If they are cached, it pulls the object from the cache. If they're not, it does another SQL request to get the full object. WPGraphQL is doing the same thing, just spread across multiple WP_Queries for more improved performance. Any WP_Query argument should still work the same as it would normally, including The issue, in this case, is just that we had added it as a default arg on the feature branch before you added your version (which is more elegant than just turning off sticky posts altogether 😂) |
I think if you can confirm removing the instance that sets it to true restores the behaviour you would expect, you can open a PR for that and we can get it merged. |
@jasonbahl sadly this doesn't solve the issue as it lies deeper than this. The querying of the posts to fetch has been changed, so that you first only fetch the ids of the posts that would be fetched for the query and then, based on this list, you fetch the actual post objects for the keys you gathered. When you pass in the When you then load the list of items based on the ids you idenfied in the first query the original context is missing, so removing The issue has been introduced in de3dd63. I'm too unfamiliar with the new DataLayer's functionality to figure out what might be a good solution to it, sadly. |
- This introduces a filter `graphql_include_sticky_posts` which will include sticky posts in the first query in a post connection query if the filter is set to true. Subsequent pages of a paginated query will not include the sticky post at the top of the results.
- This introduces a filter `graphql_include_sticky_posts` which will include sticky posts in the first query in a post connection query if the filter is set to true. Subsequent pages of a paginated query will not include the sticky post at the top of the results.
We're thinking maybe adding a field |
There's an open PR attached here, but there are some nuanced details to this. Needs deeper discussion. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This issue has been automatically closed because it has not had recent activity. If you believe this issue is still valid, please open a new issue and mark this as a related issue. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
From today's Office Hours:Assuming #863 can't be dusted off to work well enough with cursor pagination, we could use an query StickyPosts( $first: Int, $after: ID ) {
stickyPosts: posts( first: $first, after: $after, where: { isSticky:true } ) {
pageInfo {
...PageInfoFrag
}
nodes {
...PostFrag
}
}
}
query Posts( $first: Int, $after: ID ) {
posts( first: $first, after: $after, where: { isSticky: false } ) {
pageInfo {
...PageInfoFrag
}
nodes {
... postFrag
}
} and then paginate via the frontend, first through |
At first I thought, that the addition of
wp-graphql/src/Data/Connection/PostObjectConnectionResolver.php
Line 117 in 86a7d9f
brought up this error, but it seems to be way deeper than this. It appears that since 0.3.0 fetching the posts related to a query occurs in two steps: first the IDs of the posts are gathered, then the posts for the given ids are loaded.
Because of this change, sticky posts are never handled, as the querying for sticky posts is performed at a later time in wp-query.
https://github.com/WordPress/WordPress/blob/94b592ac684d7cc9a82b5ba42161d320a4c329f4/wp-includes/class-wp-query.php#L2906-L2916
When
fields
is set toids
in the query vars, the query returns before fetching and adding the sticky posts which only happens after line 3077 in class-wp-query.https://github.com/WordPress/WordPress/blob/94b592ac684d7cc9a82b5ba42161d320a4c329f4/wp-includes/class-wp-query.php#L3077
Thus sticky posts will never be handled.
To be honest I have no clue how to solve this, as this requires far deeper knowledge for the way wp-graphql loads the data, so at the moment I'm quite overwhelmed with how to solve this.
The text was updated successfully, but these errors were encountered: