Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

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?

share|improve this answer
    
Yes, thanks, I think this is the way to go. –  21zna9 Nov 18 '11 at 15:06
    
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 '11 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. –  Johannes Pille Nov 18 '11 at 15:41
    
Worked around the problem using POST and leaving the action field blank. –  21zna9 Nov 18 '11 at 16:01
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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