• Hi,

    I’ve been working with an extended class for WP_List_Table and everything is working well including the search, however the pagination isn’t working.

    While watching the network traffic I see 302 redirects for any URL that doesn’t have paged=1. So for example if I try paged=12 it redirects multiple times until it’s back at paged=1

    GET https://localhost/wp-admin/admin.php?page=options&paged=12
    302: https://localhost/wp-admin/admin.php?page=options&paged=5
    200: https://localhost/wp-admin/admin.php?page=options&paged=1

    Unfortunately I’m not familiar enough with the WP framework to know why it would be generating all these 302’s and why it seems to be doing a decreasing search of paged using odd increments.

    Any help would be appreciated. I’ve read all the associated questions on stack exchange for this but nothing seems to be similar to this problem. The total items and page numbers are correct based on my dataset. I see the get_pagenum() method reading the requested value, but then it gets 302 to another paged value until it hits 1 again.

    Thanks,
    eric

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    If the page requested is greater than what the class thinks is the total pages, it’ll 302 redirect to what it thinks is the last page. Something is apparently wrong with how the total pages is determined. In the prepare_items() method you should be calling set_pagination_args() class method with the correct values. If the pagination args are correct, you shouldn’t be getting redirects.

    Thread Starter EricB50

    (@ericb50)

    Thanks I’ll look into that.

    Thread Starter EricB50

    (@ericb50)

    I discovered the root cause and it does somewhat relate to set_pagination_args() but it is also a problem of scope which isn’t quite clear to me yet.

    There is another plugin that is extending WP_LIST_TABLE. I noticed that both that plugin and my plugin have a prepare_items routine that calls set_pagination_agrs().

    Even though the namespace appears separate to me they seem to be overriding each other. I set a page parameter inside each to return immediately from the prepare_items routine:

    
            if (isset($_GET['page'])) {
                if ($_GET['page'] != 'plugin1_options') {
                    // not viewing this table
                    return;
                }
            }

    This fixed the pagination values from being overwritten by the other extended object. I’m probably missing something but this seems like a good way to end up with conflicts in the plugins. They are declared like this:

    
    Class plugin1Table extends WP_LIST_TABLE
    Class plugin2Table extends WP_LIST_TABLE

    And each make a similar call inside their own class method of prepare_items:

    $this->set_pagination_args(array(
                'total_items' => $totalItems,
                'total_pages' => $totalPages,
                'per_page' => $perPage
            ));

    However they seem to be sharing the same pagination memory space. Is there something I can do to avoid this? I’m not sure what I’m doing wrong here but I’m new to the WP framework.

    Thanks again.

    • This reply was modified 3 years, 11 months ago by EricB50.
    • This reply was modified 3 years, 11 months ago by EricB50.
    Moderator bcworkz

    (@bcworkz)

    Interesting theory. While it’s very enticing, I don’t see how two different classes, even if extended from the same basic class, could somehow share the same memory space. Even if there were some sort of name collision, it would cause a PHP error. It’s not even a WP quirk, it’s how PHP and all OOP work. While memory overflows have been know to be possible, we usually have to try very hard to cause it. It doesn’t happen in conventional usage.

    There are numerous core extensions of WP_List_Table. None of them have displayed pagination issues.

    Oh! Maybe the shared space is not in the class per se, but in the variable to which a class object is assigned? So if I do $obj = new Foo(); and your plugin does $obj = new Bar();, my operations on my $obj could influence your $obj. So don’t look at what’s in the class for conflicts, but what is done with the class object’s assigned variable.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Getting redirection during wp_list_table pagination’ is closed to new replies.