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

Use query filter from recent posts widget #32255

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

Conversation

coreyworrell
Copy link
Contributor

Description

Added query filter from the WP_Widget_Recent_Posts to the latest posts widget. This allows for themes/plugins to alter the query. For example, if using the block in a sidebar/footer area, you could prevent the current post from showing in the list.

How has this been tested?

Not tested, but was a basic copy/paste.

Screenshots

Types of changes

New feature/bug fix. This has already been done by other blocks (archives, latest comments), etc.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • x] My code follows the accessibility standards.
  • I've tested my changes with keyboard and screen readers.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR (please manually search all *.native.js files for terms that need renaming or removal).

@github-actions
Copy link

👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @coreyworrell! In case you missed it, we'd love to have you join us in our Slack community, where we hold regularly weekly meetings open to anyone to coordinate with each other.

If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information.

@github-actions github-actions bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label May 27, 2021
@mkaz
Copy link
Member

mkaz commented Oct 16, 2021

Hi, thank you for contributing. I'm not sure if this is the approach we would want.

First, if we were to introduce a filter for the latest posts block we would want to use a new name and not reuse the widgets filter name, this can have unexpected consequence because they could be used in different scenarios.

However, I do not think we want to use a filter for the block because this is hidden and can be confusing to the user. The attributes for the latest post block can be set using the controls in the side bar, by adding a filter as another means to change the query it would override the attributes set in the block.

image

If the main reason for adding the filter is to remove the existing page, I think this might be better served as an attribute on the block that makes it visible to users and would not require any PHP code to implement as a filter.

@coreyworrell
Copy link
Contributor Author

@mkaz I agree. I used a filter to follow pattern set by the other blocks (mentioned above), but I do think an attribute is a better fit. Right now though it doesn't appear that we (theme/plugin authors) can alter the query at all, even with a Gutenberg filter or HOC?

@coreyworrell
Copy link
Contributor Author

Here is an example of how I currently accomplished this. Seems like there should be a simpler way though.

https://gist.github.com/coreyworrell/6312e13737eecec8a18d61fa8551881d

@skorasaurus skorasaurus added the [Block] Latest Posts Affects the Latest Posts Block label Feb 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Latest Posts Affects the Latest Posts Block First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants