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

Add tag selector to latest posts widget, add tag selector to queries #19755

Conversation

eriktdesign
Copy link

Description

Add a selector to filter by tags to the Latest Posts block. Modeled on the Categories filter, works the same way.

How has this been tested?

Tested in WP 5.3.2 on TwentyTwenty using Local running PHP 7.3.2. Passes the test suite. Added a file in the QueryControls module called tag-select.js -- it is a nearly exact copy of category-select.js, just changes variable names to use tags.

Screenshots

image

Types of changes

New feature: Adds a Tag selection dropdown to the "Latest Posts" block
New feature: Add tag selection to QueryControl

Checklist:

  • [X ] My code is tested.
  • [X ] My code follows the WordPress code style.
  • [X ] My code follows the accessibility standards.
  • [X ] My code has proper inline documentation.
  • [X ] I've included developer documentation if appropriate.
  • [X ] I've updated all React Native files affected by any refactorings/renamings in this PR. .

@eriktdesign
Copy link
Author

Fixes #13027

@eriktdesign
Copy link
Author

First ever PR on Gutenberg!

@eriktdesign eriktdesign changed the title Add tag selector to lastest posts widget, add tag selector to queries Add tag selector to latest posts widget, add tag selector to queries Jan 19, 2020
Copy link
Contributor

@draganescu draganescu left a comment

Choose a reason for hiding this comment

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

I have rebased and tested this and the problem is that the posts don't appear because of a bad argument to get_posts.

However even fixing that, I am unsure of tags being best selected by a dropdown, we should have an autosuggest open entry field. Tags, unlike categories, tend to be many, and that select would become impossible to track with the mouse.

@@ -25,6 +25,10 @@ function render_block_core_latest_posts( $attributes ) {
$args['category'] = $attributes['categories'];
}

if ( isset( $attributes['tags'] ) ) {
$args['tag'] = $attributes['tags'];
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
$args['tag'] = $attributes['tags'];
$args['tag_id'] = $attributes['tags'];

Copy link
Contributor

Choose a reason for hiding this comment

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

WP_Query args expect the tag argument to be one or more slugs.

export default function TagSelect( { label, noOptionLabel, tagsList, selectedTagId, onChange } ) {
const termsTree = buildTermsTree( tagsList );
return (
<TreeSelect
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if this is the best form input to use. Isn't the one used at document level tag assignment better TokenInput ?

@draganescu
Copy link
Contributor

Howdy @eriktdesign and congrats on your first PR here and welcome! I have added a review with two requests but other than that things look all right :)

This will be an important addition to the next phase of theLatestPosts block (see the overview issue #20046). Be sure to check that overview issue out as well :)

@draganescu
Copy link
Contributor

Since there has been almost a month of no activity here and given that #20785 is more advanced into implementing multiple tag filters I will close this PR. Thank you @eriktdesign. This was the base PR for #20785!

@draganescu draganescu closed this Mar 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants