Last active
December 24, 2019 08:20
-
-
Save dryan1144/480b82e6cdc70977d77b0dca20ce7690 to your computer and use it in GitHub Desktop.
Sets a transient for elements in a WP REST API call
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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