0

This is a question about a plugin.

A form to search the database works. What I am trying to do is have the search term reload into the form input field when returning search results. The problem is strange and appears to be something to do with site_url()

I am setting a variable $search_url = site_url( 'wp-admin/admin.php?page=my-plugin&action=search&searchstringSO=' . $_REQUEST["sigsearch"] ); which is the URL that is loaded with my results. Note the SO at the end of the key, that is a debug flag so I know I am looking at the right URL - I am.

The resulting URL is https://example.com/wp-admin/admin.php?page=my-plugin&action=search&searchstringSO&_wpnonce=8664768fcc notice the = and the search string are missing.

I am pretty good at trouble shooting and can't find where it is being stripped.

Things I have tried:

  • displaying the value of $_REQUEST["sigsearch"] right before creating the $search_url variable - it works
  • loading the URL string into it's own variable (which works) and then passing that to site_url()
  • adding &dummy=0 at the end - that also works

For some reason the querystring value (which is nothing more than a text string) plus the = are stripped out of the URL.

Is this a quirk of site_url() or am I missing something obvious?

  • How are you performing the search? Why do you even need to build this URL? If you have a search form then won't submitting it lead to the correct URL? I don't really understand why you need to populate the search term into the URL yourself. – Jacob Peattie Feb 14 at 8:34
  • @JacobPeattie I adopted an abandoned plugin so I have no idea why it was done the way it was originally. Adding something like a search function is tricky as I work my way through someone else's code. – Steve Feb 15 at 5:42
1

Could you try using admin_url instead of site_url you can call it the same way, but as you are trying to fetch some admin page I think that might be a better idea.

$search_url = admin_url( '/admin.php?page=my-plugin&action=search&searchstringSO=' . $_REQUEST["sigsearch"] );

Note that I removed the wp-admin prefix from the path.

  • Thanks for the suggestion. The URL still doesn't contain that pesky value. But I didn't know about admin_url so +1 – Steve Feb 15 at 5:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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