0

I have a settings page for a plugin which I created using this function:

function vsp_create_menu() { 
        add_menu_page( 'Visitors Statistics', 'Visitors Statistics', 'manage_options', 'vsp_settings_page', 'vsp_settings_page_function', plugins_url( '/images/icon.png', __FILE__ ) ); 
    } 

That created a plugin setting page.

In the settings page I am displaying some data. Instead of displaying all the data at once, I want to paginate my data, using the $_GET global variable. So, in my SQL query, the last part would be soemthing like

LIMIT $_GET['offset'], 10

So that would display 10 posts offset from whatever the GET is.

My question is how do I populate the $_GET. Because I'm not to familiar with WordPress plugin creation, I thought it would be like this...

<form id='vsp_pagination' action='<?php echo $_SERVER['PHP_SELF']; ?>' method='GET'>

But that doesn't work. When the user clicks on the submit button in the form, it take the user to

http://example.com/wp-admin/admin.php?

Basically, can anyone help me with getting some data in the _GET so I can use that data to manipulate my query? Is there a better way to do what I'm trying to do?

1 Answer 1

1

The fourth parameter of add_menu_page is the menu slug.

Hence the form action should start with: admin.php?page=vsp_settings_page, if you want to stay on said page.

If your form is correctly written, it should populate the query string in the URL. You should have probably posted all your form's markup. Is there something along the lines of

<input type="text" id="offset" name="offset" value=""/>

in it?

3
  • Ahh actually nevermind. Yes, my form doesn an an input like that, but when I put the admin.php?page=vsp_settings_page, in the action, it reloads this: example.com/wp-admin/admin.php?offset=2
    – 21zna9
    Nov 18, 2011 at 15:21
  • Sorry mate, but that should be it. I treat all my backend forms to that action (obviously w/ different slugs than 'vsp_settings_page') and it has never failed me. No idea what's wrong with your code then. You should stick to page=vsp_settings_page being the beginning of the query string for sure. Nov 18, 2011 at 15:41
  • Worked around the problem using POST and leaving the action field blank.
    – 21zna9
    Nov 18, 2011 at 16:01

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.