• Resolved drblack233

    (@drblack233)


    This is a great plugin!
    I have some questions about how to uncache in specific query after posts endpoints

    /wp/v2/posts?per_page=20&orderby=rand&page=1

    Like the above example, it can return different articles randomly, but if cached, the same article will appear when refreshed, the correct one should be cached when an article is specified, but these requests exist in posts Endpoints, relying on different query to achieve

    This annoys me, is there any good solution?
    Thanks!

    • This topic was modified 2 years, 1 month ago by drblack233.
    • This topic was modified 2 years, 1 month ago by drblack233.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Richard Korthuis

    (@rockfire)

    Hi @drblack233

    Thank you for using our plugin!

    Yes there is a solution. By using the wp_rest_cache/skip_caching filter you could make our plugin not cache any request with a random ordering:

    add_filter( 'wp_rest_cache/skip_caching', 'wprc_do_not_cache_random_order', 10, 1 );
    function wprc_do_not_cache_random_order( $skip ) {
    	if ( isset( $_GET['orderby'] ) && 'rand' === $_GET['orderby'] ) {
    		$skip = true;
    	}
    	return $skip;
    }

    But there is one catch: because of the way our plugin works, you would have to put this inside a mu-plugin that is loaded before our mu-plugin (so it should be named alphabetically before wp-rest-cache.php). So if you would place the above code in a file skip-random-cache.php inside the muplugin directory it should work.

    Thread Starter drblack233

    (@drblack233)

    Thanks! this solved my problem

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Cancel the cache under a specific Query after posts endpoints’ is closed to new replies.