-
Notifications
You must be signed in to change notification settings - Fork 43
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
Change default behavior of Homepage Posts and Carousel blocks to include posts in subcategories #1482
Conversation
… include subcategories of the selected categories. Added a toggle below the categories picker to turn this on and off.
@DennisNDean thanks for your contribution! We'll put this in our queue to test, and will get back to you shortly. |
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.
Thank you for your contribution, @DennisNDean!
It's working as described and the code looks good. A few minor changes are required before we are able to merge. They are commented inline, please let me know if you have any questions.
includes/class-newspack-blocks.php
Outdated
$args = array( | ||
$authors = isset( $attributes['authors'] ) ? $attributes['authors'] : array(); | ||
$categories = isset( $attributes['categories'] ) ? $attributes['categories'] : array(); | ||
$include_subcategories = isset( $attributes['includeSubcategories'] ) ? intval($attributes['includeSubcategories']) : false; |
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.
Lint: there should be a space before and after the arguments for intval():
intval( $attributes['includeSubcategories'] );
This is also the case for other instances in this file, see the spacing and indentation in the conditional statement, foreach loop, etc between lines 670 and 677.
You can find more information on WP coding standards here: https://github.com/WordPress/WordPress-Coding-Standards
Co-authored-by: Miguel Peixe <miguel@peixe.co>
Awesome, thank you — those changes have been made. |
includes/class-newspack-blocks.php
Outdated
$authors = isset( $attributes['authors'] ) ? $attributes['authors'] : array(); | ||
$categories = isset( $attributes['categories'] ) ? $attributes['categories'] : array(); | ||
$include_subcategories = isset( $attributes['includeSubcategories'] ) ? intval( $attributes['includeSubcategories'] ) : false; | ||
$tags = isset( $attributes['tags'] ) ? $attributes['tags'] : array(); | ||
$custom_taxonomies = isset( $attributes['customTaxonomies'] ) ? $attributes['customTaxonomies'] : array(); | ||
$tag_exclusions = isset( $attributes['tagExclusions'] ) ? $attributes['tagExclusions'] : array(); | ||
$category_exclusions = isset( $attributes['categoryExclusions'] ) ? $attributes['categoryExclusions'] : array(); | ||
$specific_posts = isset( $attributes['specificPosts'] ) ? $attributes['specificPosts'] : array(); | ||
$posts_to_show = intval( $attributes['postsToShow'] ); | ||
$specific_mode = isset( $attributes['specificMode'] ) ? intval( $attributes['specificMode'] ) : false; | ||
$args = array( |
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.
Looks like there's a double-space on $include_subcategories =
. Can you trim the extra space off from these lines?
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.
Ah yes, that's fixed, thank you
includes/class-newspack-blocks.php
Outdated
foreach ( $categories as $parent ) { | ||
$children[] = get_categories(array('child_of'=> $parent)); | ||
foreach ( $children[0] as $child ) { | ||
$categories[] = $child->term_id; |
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.
Missing a tab here
Co-authored-by: Miguel Peixe <miguel@peixe.co>
Co-authored-by: Miguel Peixe <miguel@peixe.co>
Thank you for the revisions, @DennisNDean! |
# [1.73.0-alpha.1](v1.72.0...v1.73.0-alpha.1) (2023-07-07) ### Features * add updated translation files ([#1486](#1486)) ([3a44410](3a44410)) * allow Homepage Posts and Carousel blocks to include subcategories ([#1482](#1482)) ([faa8734](faa8734)) * **modal-checkout:** render order details under different conditions ([#1485](#1485)) ([ae62734](ae62734))
🎉 This PR is included in version 1.73.0-alpha.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
# [1.73.0](v1.72.2...v1.73.0) (2023-07-17) ### Features * add updated translation files ([#1486](#1486)) ([3a44410](3a44410)) * allow Homepage Posts and Carousel blocks to include subcategories ([#1482](#1482)) ([faa8734](faa8734)) * **modal-checkout:** render order details under different conditions ([#1485](#1485)) ([ae62734](ae62734))
🎉 This PR is included in version 1.73.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
All Submissions:
Changes proposed in this Pull Request:
Change the default behavior of the Homepage Posts and Carousel blocks to include posts in subcategories of the selected categories. Added a toggle under the category picker to switch this behavior off.
Generally speaking, this is more in line with how Wordpress treats parent/child categories, where a query for the parent category is inclusive of posts in the child categories, and seems more intuitive.
Closes #207
How to test the changes in this Pull Request:
Other information: