0

I'm creating a plugin that is using the add_menu_page function to create a page for my plugin options. This means that the url for my plugins main options page is like this

http://localhost:8888/my-website/wp-admin/admin.php?page=my-wordpress-plugin

Now, in my plugin options page there is a standard form with a drop down menu that lets people choose what data they want to display.

<form>
  <select name="data-to-get">
   <option value="1">Foo</option>
   <option value="2">Bar</option>
  </select>
  <input type="submit" value="get-data">
</form>

Currently, when you select an option and click the button you are taken to this url:

http://localhost:8888/my-website/wp-admin/admin.php?data-to-get=1

This ends up loading a new page which is just blank. What I want to happen is this:

http://localhost:8888/my-website/wp-admin/admin.php?page=my-wordpress-plugin&data-to-get=1

I know that WordPress has a built in function add_query_arg so I need to do something like this:

add_query_arg( 'data-to-get', '1', 'http://localhost:8888/LFB/wp-admin/admin.php?page=lfb-player-stats' );

However, where I'm stuck is that I don't know how to hook this in. It needs to be inserted after the select value has been chosen and when the get request from the form is sent.

1 Answer 1

0

Add a hidden input field to your form with name page and value my-wordpress-plugin, When the form is submitted it will be passed along with your other form data.

<input type="hidden" name="page" value="my-wordpress-plugin">

Your Answer

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

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