• Resolved rikrook

    (@rikrook)


    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.

    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:

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

    (@erania-pinnera)

    Hi there, @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)

    (@erania-pinnera)

    Hi there, @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.