admin管理员组

文章数量:1391929

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 .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?

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/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?

Share Improve this question asked Feb 14, 2020 at 7:07 SteveSteve 2991 gold badge4 silver badges15 bronze badges 2
  • 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 Commented Feb 14, 2020 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 Commented Feb 15, 2020 at 5:42
Add a comment  | 

1 Answer 1

Reset to default 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.

本文标签: site urlQuerystring value being stripped from siteurl()