Is it possible to get post metadata of referring page?

I’m trying to direct a php authorization script to act if the page that referred to it belongs to a certain category (free).

Is there something other than <?php wp_get_referer() ?> that will return more than the url? I basically need to get the id of the referrer.

Related posts

1 comment

  1. url_to_postid(wp_get_referer()) will give you the ID of the referring page/post if you were referred from a page or a post. It won’t work if referred from some other types of pages, like archives.

    You will then need to retrieve the categories for the ID to see if they match.

    I would strongly consider passing a parameter with the request though. You should already have the post ID and possibly the post data on the referring page and won’t have to make separate queries to grab it.

    You can use a nonce to help prevent abuse of the parameter– that is, to prevent someone from just typing ?status=free into the URL.

    You mention sessions in a comment. I have used sessions successfully in WordPress and with little trouble. Be aware that a lot of people complain about sessions with WordPress.


Comments are closed.