Reputation: 2781
I am creating a plugin; the plugin has item listings, and I want to search for items in the listings.
Here is my code:
<form method="get" action="<?php echo admin_url('admin.php?page=listing'); ?>" id="search" >
<input type="text" name="q" placeholder='Search'/>
</form>
When I submit the form, the URL redirects to:
http://localhost/wordpress/wp-admin/admin.php?q=shock
And no search occurs! How do I fix this?
Upvotes: 0
Views: 54
Reputation: 3120
Your page
parameter gets erased.
You are using a GET
method and q
parameter overrides all other parameters in a query string, which is page=listing
.
Two possible solutions:
use POST
by setting method="post"
attribute, in which case q
will be passed as a POST parameter to a page with URL .../admin.php?page=listing
.
include the page
parameter inside your form (<input type="hidden" name="page" value="listing"/>
) and replace admin_url('admin.php?page=listing');
with admin_url('admin.php');
, in which case you'll end up on .../admin.php?page=listing&q=shock
, because your form will contain both q
and page
parameters.
The choice really depends on how your plugin obtains the search string: GET or POST parameter.
Upvotes: 1