I am developing pagination for a list of posts in my plugin. I've added a custom parameter in my plugin_functions.php file:

add_query_arg('pworkspage', 1);

As you can see it defaults to "1". Now, whenever I visit the custom admin page of my plugin with that parameter in the URL (www.example.com/wp-admin/admin.php?page=mycustompage&pworkspage=2) my script can't see the parameter at all.

I am retrieving the parameter like this:

$page_nr = get_query_var('pworkspage', 1);

The variable $page_nr is equal to string(0) "".

I tried a different approach using the query_vars filter but I got the same results.

Am I doing something wrong?


Query vars are for use in the main $wp_query query object, your custom admin page has no main query, so no vars are parsed into a query object that can be accessed via get_query_var. I don't think there's anything WordPress-specific that can be used in this case, I would just access the value via $_GET.

  • 1
    Yep, best bet is to ignore WordPress on your own custom page. – WraithKenny Nov 30 '15 at 19:26
  • Okay, thank you. That's very informative. I think that the WordPress codex should be updated with your answer. Are there any tips about sanitizing $_GET parameters that are going to be used in that place? – Pe-Ter Nov 30 '15 at 19:28
  • 1
    The Data Validation Codex page has a lot of useful info on that subject. – Milo Nov 30 '15 at 19:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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