I can’t fetch query parameters ($_GET parameters) with get_query_var

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?

1 Answer
1

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.

Leave a Comment