Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 9, 2025

The media library's infinite scroll and load more button were broken because the custom query-attachments AJAX handler returned only the posts array, missing pagination metadata that WordPress's media views require.

Changes

  • Modified wp_media_categories_ajax_query_attachments() to return pagination metadata alongside posts:
    • total: Total posts found ($query->found_posts)
    • max_num_pages: Maximum page count ($query->max_num_pages)

This matches WordPress core's response structure:

// Before
wp_send_json_success( $posts );

// After
wp_send_json_success( array(
    'posts'         => $posts,
    'total'         => $query->found_posts,
    'max_num_pages' => $query->max_num_pages
) );

Without max_num_pages, the media library cannot determine if more items exist to load.

Original prompt

This section details on the original issue you should resolve

<issue_title>Broken Loading</issue_title>
<issue_description>The infinite loading (and fall back load more button) are both not working when this plugin is active. I don't mind hitting the load more button if we can actually browse the media library. </issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Fix broken loading for media library plugin Fix infinite scroll and load more button by including pagination metadata in AJAX response Dec 9, 2025
Copilot AI requested a review from JJJ December 9, 2025 03:42
@JJJ JJJ marked this pull request as ready for review December 9, 2025 04:15
Copilot AI review requested due to automatic review settings December 9, 2025 04:15
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes the broken infinite scroll and "load more" button in the media library by including essential pagination metadata in the AJAX response. The plugin's custom query-attachments handler was only returning the posts array, which prevented WordPress's media views from determining if more items existed to load.

  • Modified the AJAX response structure to include total (found_posts) and max_num_pages fields alongside the posts array
  • Aligns the response format with WordPress core's expectations for media library pagination

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

Broken Loading

2 participants