Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sets a transient for elements in a WP REST API call
<?php
function yournamespace_rest_transient_example() {
//check for transient first
$data = get_transient( 'yournamespace_data_example' );
if ( !empty( $data ) ) {
$data = $terms_transient;
//generate output and then save to transient
} else {
//do some stuff here and set result to $data
$data = custom_remote_post_call();
//cache for 2 days
set_transient( 'yournamespace_data_example', $data, DAY_IN_SECONDS * 2 );
}
$result = new WP_REST_Response( $data, 200 );
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.