1

I am displaying a list of posts in the plugin backend but I can't seem to get the pagination to work. I used the standard approach of getting the "paged" variable and then passing it to get_posts()'s arguments, but whenever I visit my custom backend page or subpage and add the &page=2 variable I get that permissions error about not having enough of them to visit that page.

Is there a special way to apply pagination in the backend?

2
  • What context are you doing this in? Is it on a post edit page? Options page? Generic admin page?
    – Tom J Nowell
    Commented Nov 29, 2015 at 23:46
  • @TomJNowell Custom submenu page added with add_submenu_page whose parent is a custom page added with add_menu_page.
    – NakedCat
    Commented Nov 29, 2015 at 23:48

1 Answer 1

0

In the admin back-end of a plugin, you can't use the query_vars hook and the get_query_var built in function since the page itself is a query parameter. To get around this, I simply add a new query parameter to the end of your plugin page link called, '&pagenum=#" and I pull it out manually using:

$pagenum = isset( $_GET['pagenum'] ) ? absint( $_GET['pagenum'] ) : 1;

There might be a better way of doing this, but I haven't found one that requires less effort.

Here is what the plugin url might look like:

admin.php?page=[plugin-dir]%2F[plugin-slug].php&pagenum=1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.