Skip to content

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

Merged
merged 2 commits into from
Mar 10, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/block-library/src/query-total/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function render_block_core_query_total( $attributes, $content, $block ) {
}

$max_rows = $query_to_use->found_posts;
Copy link
Member

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think found_posts is already set as int on the query object.

Copy link
Member

Choose a reason for hiding this comment

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

I confirmed that found_posts is always set as int.

What about $current_page = max( 1, get_query_var( 'paged', 1 ) );? In particular, I'm worried about get_query_var as it has a mixed return value.

$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;
Expand Down
Loading