mardi 30 décembre 2014

Appending parameters to WordPress query string in backend


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.





Aucun commentaire:

Enregistrer un commentaire