[wp-trac] [WordPress Trac] #39968: Media Library: deleting all items on the last page loses the pagination/navigation buttons and shows message

WordPress Trac noreply at wordpress.org
Mon Aug 31 21:07:34 UTC 2020


#39968: Media Library: deleting all items on the last page loses the
pagination/navigation buttons and shows message
--------------------------+-----------------------------
 Reporter:  donsony       |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Future Release
Component:  Media         |     Version:  4.7.2
 Severity:  normal        |  Resolution:
 Keywords:  has-patch     |     Focuses:  ui
--------------------------+-----------------------------
Changes (by Mista-Flo):

 * keywords:  needs-patch => has-patch


Comment:

 Hi there, it took me ages to understand what was wrong here.

 For example, if you have just two pages of attachments and you are on page
 2, just change the paged argument in the URL to 37 and it still loads the
 UI with no attachments at all.

 After some digging, I have found out that `$wp_query->found_posts` and
 `$wp_query->max_num_pages` are equal to 0.

 So even if it's on page 450 that does not exist, the posts list table have
 a count of the number of total posts which helps to identify the maximum
 number of pages in the pagination and redirect to the last existing page
 if the requested page is too high, check `set_pagination_args` function in
 `wp-admin/includes/class-wp-list-table.php` for more information.

 So finally I just used the `wp_count_attachments()` function to mimic the
 behaviour of the post list table and it worked.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/39968#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list