-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Blocks: Add helper functions for Terms Query pagination #10872
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
base: trunk
Are you sure you want to change the base?
Changes from all commits
362bc16
0267d23
f51ed15
ee7cb46
c83882d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3049,6 +3049,63 @@ function get_comments_pagination_arrow( $block, $pagination_type = 'next' ) { | |||||||||||||
| return null; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| /** | ||||||||||||||
| * Builds query vars for terms from a Terms Query block instance. | ||||||||||||||
| * | ||||||||||||||
| * It's used with the Terms Query inner blocks (Term Template, Terms Query Pagination). | ||||||||||||||
| * | ||||||||||||||
| * @since 7.0.0 | ||||||||||||||
| * | ||||||||||||||
| * @param WP_Block $block Block instance. | ||||||||||||||
| * @return array<string, mixed> Query vars suitable for get_terms() or wp_count_terms(). | ||||||||||||||
| */ | ||||||||||||||
| function build_terms_query_vars_from_block( WP_Block $block ): array { | ||||||||||||||
| $query = $block->context['termQuery']; | ||||||||||||||
|
|
||||||||||||||
| $query_vars = array( | ||||||||||||||
| 'number' => $query['perPage'], | ||||||||||||||
| 'order' => $query['order'], | ||||||||||||||
| 'orderby' => $query['orderBy'], | ||||||||||||||
| 'hide_empty' => $query['hideEmpty'], | ||||||||||||||
| ); | ||||||||||||||
|
|
||||||||||||||
| $inherit_query = isset( $query['inherit'] ) && $query['inherit'] && ( is_tax() || is_category() || is_tag() ); | ||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor enhancement for conciseness:
Suggested change
|
||||||||||||||
|
|
||||||||||||||
| if ( $inherit_query ) { | ||||||||||||||
| // Get the current term and taxonomy from the queried object. | ||||||||||||||
| $queried_object = get_queried_object(); | ||||||||||||||
|
Comment on lines
+3074
to
+3076
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This avoids PHPStan warning about possible accessing a non-existent property:
Granted, this shouldn't actually be the case due to the
Suggested change
|
||||||||||||||
|
|
||||||||||||||
| // For hierarchical taxonomies, show children of the current term. | ||||||||||||||
| // For non-hierarchical taxonomies, show all terms (don't set parent). | ||||||||||||||
| if ( is_taxonomy_hierarchical( $queried_object->taxonomy ) ) { | ||||||||||||||
westonruter marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||
| // If showNested is true, use child_of to include nested terms. | ||||||||||||||
| // Otherwise, use parent to show only direct children. | ||||||||||||||
| if ( ! empty( $query['showNested'] ) ) { | ||||||||||||||
| $query_vars['child_of'] = $queried_object->term_id; | ||||||||||||||
| } else { | ||||||||||||||
| $query_vars['parent'] = $queried_object->term_id; | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
| $query_vars['taxonomy'] = $queried_object->taxonomy; | ||||||||||||||
| } else { | ||||||||||||||
| // If not inheriting set `taxonomy` from the block attribute. | ||||||||||||||
| $query_vars['taxonomy'] = $query['taxonomy']; | ||||||||||||||
|
|
||||||||||||||
| // If we are including specific terms we ignore `showNested` argument. | ||||||||||||||
| if ( ! empty( $query['include'] ) ) { | ||||||||||||||
| $query_vars['include'] = array_unique( array_map( 'intval', $query['include'] ) ); | ||||||||||||||
| $query_vars['orderby'] = 'include'; | ||||||||||||||
| $query_vars['order'] = 'asc'; | ||||||||||||||
| } elseif ( is_taxonomy_hierarchical( $query['taxonomy'] ) && empty( $query['showNested'] ) ) { | ||||||||||||||
| // We set parent only when inheriting from the taxonomy archive context or not | ||||||||||||||
| // showing nested terms, otherwise nested terms are not displayed. | ||||||||||||||
| $query_vars['parent'] = 0; | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| return $query_vars; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| /** | ||||||||||||||
| * Strips all HTML from the content of footnotes, and sanitizes the ID. | ||||||||||||||
| * | ||||||||||||||
|
|
||||||||||||||

Uh oh!
There was an error while loading. Please reload this page.