Title: Serve different cache based on GET parameter
Last modified: February 21, 2024

---

# Serve different cache based on GET parameter

 *  Resolved [rikrook](https://wordpress.org/support/users/rikrook/)
 * (@rikrook)
 * [2 years, 3 months ago](https://wordpress.org/support/topic/serve-different-cache-based-on-get-parameter/)
 * I have content that is only available trough a newsletter, the URL in the newsletter
   adds a query parameter. lets say [https://foobar.com/my-post/?my_query_param=12345](https://foobar.com/my-post/?my_query_param=12345).
 * If i come on the page WITH my query parameter i should be able to read the post
   and its content without a paywall. If i come on the page without the query parameter
   i should get a paywall. This works without caching.
 * Now i have added a dynamic caching plugin altering the cache key with the cacheaction
   wp_cache_key. The code looks like this:
 *     ```wp-block-code
       //Get query parameter if it is present in the URL
       $inputString = $_SERVER['QUERY_STRING'];
       $parameters = [];
       parse_str($inputString, $parameters);
       //This is either INT, 0 or false.
       $my_query_param = isset($parameters['my_query_param']) ? intval($parameters['my_query_param']) : false;
   
       if( !is_user_logged_in() ) {
           if( $my_query_param === false ) {
               //No query parameter, paywall
               return $slug .= '_not_logged_in';
           } else if( $my_query_param === 0 ){
               //Invalid parameter, paywall
               return $slug .= '_not_logged_in_newsletter';
           } else{
               //Content without paywall
               return $slug .= '_not_logged_in_free_content';
           }
       }
       ```
   
 * so $my_query_param can be a number, 0 or false. I get a different cache key in
   either situation. However a post without the query parameter gets served the 
   same cache when i visit the same post WITH a query parameter.
 * I believe this is a bug but if i am missing something i would appreciate the 
   solution.

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Support [Stef (a11n)](https://wordpress.org/support/users/erania-pinnera/)
 * (@erania-pinnera)
 * [2 years, 3 months ago](https://wordpress.org/support/topic/serve-different-cache-based-on-get-parameter/#post-17471225)
 * Hi there, [@rikrook](https://wordpress.org/support/users/rikrook/),
 * For WP Super Cache to serve different cached content based on the GET parameter,
   you will need to modify the settings to make caching aware of the query strings.
   In your use case where you want to serve different content based on the `my_query_param`
   parameter, you need to ensure that WP Super Cache is set up to cache requests
   with GET parameters separately.
 * Please have a look at the WP Super Cache settings—particularly the section on
   rejecting or accepting URLs with query parameters. You might need to add `my_query_param`
   to the list of accepted query strings in the plugin’s settings to ensure it caches
   different versions based on the presence and value of that parameter.
 * If that doesn’t help and you still think that’s a bug, we can investigate further.
 * Let me know what you find out!
 *  Plugin Support [Stef (a11n)](https://wordpress.org/support/users/erania-pinnera/)
 * (@erania-pinnera)
 * [2 years, 3 months ago](https://wordpress.org/support/topic/serve-different-cache-based-on-get-parameter/#post-17492684)
 * Hi there, [@rikrook](https://wordpress.org/support/users/rikrook/),
 * I’m going to mark this thread as solved. If you have any further questions or
   need more help, you’re welcome to open another thread here. Cheers!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Serve different cache based on GET parameter’ is closed to new replies.

 * ![](https://ps.w.org/wp-super-cache/assets/icon-256x256.png?rev=3506220)
 * [WP Super Cache](https://wordpress.org/plugins/wp-super-cache/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-super-cache/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-super-cache/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-super-cache/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-super-cache/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-super-cache/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [Stef (a11n)](https://wordpress.org/support/users/erania-pinnera/)
 * Last activity: [2 years, 3 months ago](https://wordpress.org/support/topic/serve-different-cache-based-on-get-parameter/#post-17492684)
 * Status: resolved