Skip to content

Set the media attachments query posts per page conditionally. - #12838

Open
afercia wants to merge 1 commit into
WordPress:trunkfrom
afercia:media-query-conditional-posts-per-page
Open

Set the media attachments query posts per page conditionally.#12838
afercia wants to merge 1 commit into
WordPress:trunkfrom
afercia:media-query-conditional-posts-per-page

Conversation

@afercia

@afercia afercia commented Aug 4, 2026

Copy link
Copy Markdown
Member

Trac ticket: https://core.trac.wordpress.org/ticket/65564, https://core.trac.wordpress.org/ticket/65850

Sets the posts_per_oage arg conditionally in the media attachments browser based on whether Infinite scrolling is enabled (40) or the 'Load more' button is enabled instead (80),

Note that the defaultArgs.posts_per_page is meant to be static so the logic to set the posts_per_page value conditionally is added later where it is used, in the get() method.

Use of AI Tools

None


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props afercia, wildworks, tyxla.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adjusts the media attachments query pagination defaults so the number of items requested per query matches the UI mode (infinite scroll vs. “Load more”) in the media library experience.

Changes:

  • Updates defaultArgs.posts_per_page to 40 as the baseline default.
  • Conditionally sets args.posts_per_page to 80 in Query.get() when infinite scrolling is disabled.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +285 to +287
if ( wp.media && wp.media.view && wp.media.view.settings && wp.media.view.settings.infiniteScrolling === 0 ) {
args.posts_per_page = 80;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I believe this point is valid. For example, the media gallery applies perPage-1, which could unintentionally overwrite this.

Furthermore, I believe that checking for infiniteScrolling === 0 is too strict. This is because it may lead to mismatches if media_view_settings filters set the value to false or "0", as these do not align with the strict equality check. See https://github.com/t-hamano/wordpress-develop/blob/57b8740a0a9b0f65333ff0b6aaa9c5ff66232f89/src/js/media/views/attachments/browser.js#L80

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I second this. It's very important to preserve any perPage / posts_per_page that override the defaults.

// Fill any other default query args.
_.defaults( args, Query.defaultArgs );

// When 'Load more' is enabled, increase the posts pr page to 80.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Valid catch

@t-hamano
t-hamano requested a review from tyxla August 14, 2026 14:23
Comment on lines +285 to +287
if ( wp.media && wp.media.view && wp.media.view.settings && wp.media.view.settings.infiniteScrolling === 0 ) {
args.posts_per_page = 80;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I second this. It's very important to preserve any perPage / posts_per_page that override the defaults.

_.defaults( args, Query.defaultArgs );

// When 'Load more' is enabled, increase the posts pr page to 80.
if ( wp.media && wp.media.view && wp.media.view.settings && wp.media.view.settings.infiniteScrolling === 0 ) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I believe we should use ! wp.media.view.settings.infiniteScrolling instead of wp.media.view.settings.infiniteScrolling === 0 to match the existing convention as the rest of the UI.

// Fill any other default query args.
_.defaults( args, Query.defaultArgs );

// When 'Load more' is enabled, increase the posts pr page to 80.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Valid catch

@afercia

afercia commented Aug 14, 2026

Copy link
Copy Markdown
Member Author

I'm all for improvements and I will leave it in your hands.
Just noting that a final feedback about performance, which is the most important part, is still pending.

There are some performance related considerations in the two related tickets:
https://core.trac.wordpress.org/ticket/65564#comment:40
https://core.trac.wordpress.org/ticket/65850#comment:1

but I'm not seeing a final word on ti.

@t-hamano

Copy link
Copy Markdown
Contributor

I'm all for improvements and I will leave it in your hands.

We can take over the task if necessary, but what is the reason you cannot continue working on it?

@afercia

afercia commented Aug 15, 2026

Copy link
Copy Markdown
Member Author

We can take over the task if necessary, but what is the reason you cannot continue working on it?

I'm not comfortable with answering your question publicly on this issue.

@t-hamano

Copy link
Copy Markdown
Contributor

I'm not comfortable with answering your question publicly on this issue.

I have no idea why you're taking that attitude, but I'm going to move this PR forward anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants