Haven’t worked much with XML so I’m hitting a bit of a wall:
function getapi()
{
$api_response = wp_remote_get( "http://example.com/getXML" );
$data = wp_remote_retrieve_body( $api_response );
$output = new SimpleXMLElement ($data );
return $output;
}
Get or set the Transient
function transient()
{
$transient = get_transient( 'transient_value' );
if ( ! $transient ) {
$transient = getapi();
set_transient( 'transient_value', $transient, 180 );
}
return $transient;
}
I can easily show the data, but calling it up from a stored transient results in this error being shown:
Node no longer exists in C:xampplitehtdocs...
Not sure what the extra step is that I need to perform in order to store the data correctly.
Many thanks!
Noel
According to this ticket:
When you are storing object in transient it gets serialized and not all objects are capable of that correctly.
Store textual XML data in transient instead.