-
Notifications
You must be signed in to change notification settings - Fork 442
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
#786 - Support sticky posts if enabled #863
base: develop
Are you sure you want to change the base?
Conversation
- 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.
Wouldn't this be more flexible as a query arg? |
Is it already morning there? 😱 |
@epeli maybe both. 🤔 My thought was that as a maintainer of a server you may not want to support exposing sticky posts. But on the flip side, as a consumer you may want to be able to ask for them 🤔 I’m open to feedback for sure. My thought still is that it feels a bit more like the domain of the server to decide rather than the consumer. 🤔 |
8.30am ;) Consider this scenario: I want to list all posts whether they are sticky or not by the publish date and create a second list of only sticky posts to a sidebar. If server makes this decision that would be impossible with a single graphql query. |
Any news about that? I can't query for sticky posts... |
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. |
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. |
@@ -62,7 +62,30 @@ public function get_query() { | |||
* @return array | |||
*/ | |||
public function get_items() { | |||
return ! empty( $this->query->posts ) ? $this->query->posts : []; | |||
|
|||
$sticky = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces must be used to indent lines; tabs are not allowed
$sticky = []; | ||
|
||
/** | ||
* Sticky posts are only supported for the 'post' post_type, and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces must be used to indent lines; tabs are not allowed
|
||
/** | ||
* Sticky posts are only supported for the 'post' post_type, and | ||
* should only be added to the first query for posts in a paginated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces must be used to indent lines; tabs are not allowed
/** | ||
* Sticky posts are only supported for the 'post' post_type, and | ||
* should only be added to the first query for posts in a paginated | ||
* query |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces must be used to indent lines; tabs are not allowed
* should only be added to the first query for posts in a paginated | ||
* query | ||
*/ | ||
if ( 'post' === $this->post_type && 0 == $this->get_offset() && ! isset( $this->args['last'] ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces must be used to indent lines; tabs are not allowed
Code Climate has analyzed commit 089d3f3 and detected 31 issues on this pull request. Here's the issue category breakdown:
View more on Code Climate. |
Closes #786
This adds a new
graphql_include_sticky_posts
filter. Default isfalse
, but if set totrue
WPGraphQL will include sticky posts at the top of Post Object queries (of the "post" post_type).For paginated queries, the sticky post will only be included in the first query of forward paginated queries.