-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Query Total: Prevent stricted type fatal errors on post per page. #69508
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
Changes from all commits
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 |
---|---|---|
|
@@ -23,15 +23,15 @@ function render_block_core_query_total( $attributes, $content, $block ) { | |
$wrapper_attributes = get_block_wrapper_attributes(); | ||
if ( isset( $block->context['query']['inherit'] ) && $block->context['query']['inherit'] ) { | ||
$query_to_use = $wp_query; | ||
$current_page = max( 1, get_query_var( 'paged', 1 ) ); | ||
$current_page = max( 1, (int) get_query_var( 'paged', 1 ) ); | ||
} else { | ||
$page_key = isset( $block->context['queryId'] ) ? 'query-' . $block->context['queryId'] . '-page' : 'query-page'; | ||
$current_page = isset( $_GET[ $page_key ] ) ? (int) $_GET[ $page_key ] : 1; | ||
$query_to_use = new WP_Query( build_query_vars_from_query_block( $block, $current_page ) ); | ||
} | ||
|
||
$max_rows = $query_to_use->found_posts; | ||
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. Should we also cast this value just to be on the safe side? 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. I think 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. I confirmed that What about |
||
$posts_per_page = $query_to_use->get( 'posts_per_page' ); | ||
$posts_per_page = (int) $query_to_use->get( 'posts_per_page' ); | ||
|
||
// Calculate the range of posts being displayed. | ||
$start = ( $current_page - 1 ) * $posts_per_page + 1; | ||
|
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.
The
get_query_var
also usesWP_Query::get
under the hood and ``min( 1, '0' )will return
"0"`.