Forum Replies Created

Viewing 1 replies (of 1 total)
  • Shoutout to @mustafamsy and @rockfire, THANKS! It was exactly my problem. The condition strpos did not really work for me to differentiate between the different object types and between my endpoints. So I decided to share the code I used:

    
    function wprc_determine_object_type( $object_type, $cache_key, $data, $uri) {
    	if ( $object_type !== 'unknown' || strpos( $uri, 'api/v2' ) === false ) {
    		return $object_type;
    	}
    	elseif ( $object_type == 'unknown' && $uri === 'MATCH_EXACT_uri/posts' ) {
    		return 'post';
    	}
    	elseif ( $object_type == 'unknown' && $uri === 'MATCH_EXACT_uri/pages' ) {
    		return 'page';
    	}
    
    	return 'unknown';
    }
    add_filter( 'wp_rest_cache/determine_object_type', 'wprc_determine_object_type', 10, 4 );
    
    
Viewing 1 replies (of 1 total)