Just use wp_get_referer()
, and a few other functions to get the simple name of the referring page, e.g.
if (basename(parse_url(wp_get_referer(), PHP_URL_PATH)) == 'my-search-page') {
(Or you could use string searching or matching instead of parse_url
and basename
).
(Also note wp_get_referer
is deliberately misspelled. It originates in a misspelling in one of the web standards)
Addendum
Might have to tweak this a bit to deal with the case where there’s no referrer (e.g. a bookmark was used to get to the page).