• Resolved Bruno Braga

    (@brunobragaw8t)


    Hi

    Our team would like for the cache entry to be cleared depending on updates of 2 or more post types.

    Is this possible? If so, how?

    We tried passing it an array and a comma-separated string. None of these worked.

    Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Richard Korthuis

    (@rockfire)

    Hi @brunobragaw8t

    Thank you for using our plugin!

    We do not have support for multiple post types per cache record at this time. You could however achieve the same result with a simple filter where you clear the caches of posttype2 if posttype1 is saved (and the other way around):

    add_filter( 'save_post', 'wprc_clear_caches_on_save', 10, 2 );
    
    function wprc_clear_caches_on_save( $post_id, $post ) {
        if ( 'auto-draft' === $post->post_status || ! in_array( $post->post_type, [ 'postype1', 'posttype2' ] ) {
            return;
        }
    
        $post_type = ( 'posttype1' === $post->post_type ? 'posttype2' : 'posttype1' );
        $caching = \WP_Rest_Cache_Plugin\Includes\Caching\Caching::get_instance();
        $caching->delete_object_type_caches( $post_type  );
    }

    N.B. I typed this without testing it, so there may be some small errors in it, but the principle would remain the same.

    Thread Starter Bruno Braga

    (@brunobragaw8t)

    Hi!

    That’s actually exactly what we ended up doing in order to get around the issue.

    Thanks for the reply anyway!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Multiple object types’ is closed to new replies.