Skip to content
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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

jasonbahl
Copy link
Collaborator

Closes #786

This adds a new graphql_include_sticky_posts filter. Default is false, but if set to true 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.

- 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.
@esamattis
Copy link
Collaborator

Wouldn't this be more flexible as a query arg?

@jasonbahl
Copy link
Collaborator Author

Is it already morning there? 😱

@jasonbahl
Copy link
Collaborator Author

jasonbahl commented May 23, 2019

@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.

🤔

@esamattis
Copy link
Collaborator

esamattis commented May 23, 2019

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.

@jasonbahl jasonbahl added this to To Prioritize in 4: Actionable Issues Aug 7, 2019
@AlbertoAbruzzo
Copy link

Any news about that? I can't query for sticky posts...

@stale
Copy link

stale bot commented Aug 2, 2022

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.

@stale stale bot added the stale label Aug 2, 2022
@stale
Copy link

stale bot commented Sep 1, 2022

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.

@stale stale bot closed this Sep 1, 2022
@justlevine justlevine reopened this Sep 2, 2022
@stale stale bot removed the stale label Sep 2, 2022
@stale
Copy link

stale bot commented Dec 1, 2022

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.

@stale stale bot added the Stale? May need to be revalidated due to prolonged inactivity label Dec 1, 2022
@stale
Copy link

stale bot commented Mar 1, 2023

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.

@stale stale bot closed this Mar 1, 2023
@justlevine justlevine reopened this Mar 1, 2023
@@ -62,7 +62,30 @@ public function get_query() {
* @return array
*/
public function get_items() {
return ! empty( $this->query->posts ) ? $this->query->posts : [];

$sticky = [];
Copy link

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
Copy link

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
Copy link

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
Copy link

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'] ) ) {
Copy link

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

@codeclimate
Copy link

codeclimate bot commented Mar 1, 2023

Code Climate has analyzed commit 089d3f3 and detected 31 issues on this pull request.

Here's the issue category breakdown:

Category Count
Style 31

View more on Code Climate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Stale? May need to be revalidated due to prolonged inactivity
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sticky Posts are not being handled anymore in 0.3.0
4 participants