Skip to content

Commit

Permalink
Query loops that inherit template settings for posts per page should …
Browse files Browse the repository at this point in the history
…update via temporary edits (#63358)

Unlinked contributors: Sirjazzfeetz.

Co-authored-by: jeryj <[email protected]>
Co-authored-by: scruffian <[email protected]>
Co-authored-by: jameskoster <[email protected]>
  • Loading branch information
4 people authored Jul 16, 2024
1 parent 9cbdf26 commit be88047
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions packages/block-library/src/query/edit/query-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,26 @@ export default function QueryContent( {
} );
const { postsPerPage } = useSelect( ( select ) => {
const { getSettings } = select( blockEditorStore );
const { getEntityRecord, canUser } = select( coreStore );
const { getEntityRecord, getEntityRecordEdits, canUser } =
select( coreStore );
const settingPerPage = canUser( 'read', {
kind: 'root',
name: 'site',
} )
? +getEntityRecord( 'root', 'site' )?.posts_per_page
: +getSettings().postsPerPage;

// Gets changes made via the template area posts per page setting. These won't be saved
// until the page is saved, but we should reflect this setting within the query loops
// that inherit it.
const editedSettingPerPage = +getEntityRecordEdits( 'root', 'site' )
?.posts_per_page;

return {
postsPerPage: settingPerPage || DEFAULTS_POSTS_PER_PAGE,
postsPerPage:
editedSettingPerPage ||
settingPerPage ||
DEFAULTS_POSTS_PER_PAGE,
};
}, [] );
// There are some effects running where some initialization logic is
Expand Down

0 comments on commit be88047

Please sign in to comment.