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.
See:
Related Posts:
- Initialize WordPress environment to use in command line script
- Creating a Dynamic Path to wp-blog-header.php
- Problem accessing wp-load.php
- How to load wordpress environment without loading the template?
- WordPress function gives different results outside vs inside PHPUnit test
- How to avoid wp-load.php within a PHP/CSS file?
- How to efficiently load and use the wordpress API from outside the original structure
- Best way to load WordPress Bootstrap
- Check user logged in from outside of WP folder
- wp-load.php not working
- WP_load, shortinit for wordpress Ajax
- WordPress Nexus Theme front-end editor broken because cannot find wp-load.php [closed]
- Fetching latest posts from 2 different WP installations
- Loading wp-load.php in an external PHP file throws unknown error
- Which position is after `wp-load.php`?
- Exploiting WordPress Core Functionality for Development
- How to include wp-load.php and have all plugins load as well
- content of the page is not displaying getting empty page [closed]
- What is the correct way to use WordPress functions outside WordPress files?
- What is the very earliest action hook you can call?
- How to load WordPress on non WP page?
- Displaying content from one WP site on separate WP site
- When is wp_loaded initiated only with admin or only when user enters the site or both?
- What is the best way to load the WP environment in a subdomain of my multisite WordPress install?
- WP-Admin not working properly at WordPress multisite with subdirectories
- Notice: map_meta_cap was called incorrectly
- Initialize WordPress environment to use in a real cron script
- Trying to avoid including wp-load.php
- Why I have this error when I try to install this old blog on my local webserver?
- Create a post variable processing page
- external wordpress pages using wp-blog-header
- Looking for a better way to handle an ajax script that pulls in post data on click
- do_action and hook methods
- update_option not working in stand-alone PHP script
- Get current user data from external PHP page
- wp_enqueue_style with style.php and WordPress functions
- Admin first hook that outputs HTML?
- How do you load WordPress from an external script when using MultiSite? [duplicate]
- Call to undefined function issue
- Include user defined styles without including wp-load
- wp-load Without Loading the plugins
- How to avoid loading wp-load.php from external php scripts?
- Include CSS with PHP without including wp-load?
- Open Post Thumbnail in New Child Theme File in WordPress
- Accessing the database from a plugin outside of action hooks
- Issue using wp-load.php in WordPress Plugin Development
- Use wordpress functions in another PHP file
- how to upload a image from frontend with wp_insert_post and also update_post_meta?
- How to access $menu variable in custom .PHP file that loads wp-load.php?
- getting logged in user info (wp-load.php) from parent directory
- Cron job script – loading wordpress system fails
- Programmatically inserting post through URL – when including wp-load.php, it’s redirecting to wp-admin/install.php
- WordPress server change – slow admin login time for first time
- Load wordpress content in other domain
- Why I have this error when I try to install this old blog on my local webserver?
- Access bloginfo, get_option, and plugins_url from a non-core php file
- WP CLI can’t delete plugin related table
- Using wpdb without loading all plug-ins via wp-load.php
- What hook is the currently active theme’s functions.php file loaded on? [duplicate]
- Use wp-load() and wp_head() to render a page’s header outside of WordPress
- Load Next WordPress Posts With AJAX?
- Take control of WordPress before functions.php
- wp-load.php redeclares classes
- Why does WP load so many files in the head of source code? How do I optimize it?
- How can I call wp-load.php in my plugin file
- Proper way to use WordPress function with AJAX PHP file
- I need a standalone script in web root but still have access to the database
- External PHP file & Pretty Permalink
- WordPress and IPN problem
- PHP mobile redirect Endless loop
- Including ‘wp-load.php’ after another include() generates an error
- Subdomain redirect problem
- How to add a custom filter (by coding) before access one wordpress page ? And where to call the custom filter?
- Hook from plugin doesn’t fire up from external PHP script
- I created a plugin with ‘view page’ that uses MYSQL + PHP. When I use wp_insert_post(), it turns everything to HTML
- How to load WordPress on non WP page?
- WordPress custom php script to match standard page layout
- how to define a html folder to make it work with WordPress commands
- Getting Fatal error: Uncaught Error: Call to undefined function plugin_dir_path() when linking to another file within my wordpress plugin
- Doesn’t call user information to include “wp-load.php” in an external php file
- How to get option values without requiring wp-load?
- Causing my WordPress functions to execute twice
- Error establishing a database connection – after updating DNS
- Retrieve data from multiple WordPress sites using PHP script
- Rewritten URL not loading WordPress environment
- What is the best practice to initialise $wpdb by loading wp-load.php?
- Manually cache a special, non-WP-but-using-WP page (e.g. Ajax results) with W3TC
- Using actions, hooks and filters in a non-WordPress page
- Get wp-load.php PATH with wp_localize_script and JavaScript for plugin
- Why I have this error when I try to install this old blog on my local webserver?
- Frontend file upload works, but I get error “Constant ABSPATH already defined”
- To call hook on a php external file
- Get Core Functionality from Within a (Secondary) Plugin File
- WordPress repository forbids me call wp-load.php in non-WordPress file
- What is Global WordPress Objects?
- wordpress login blank screen [closed]
- how to use header function in wp-load.php file [closed]
- Sessions in word press [duplicate]
- Use ajax response in PHP function