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:\xampplite\htdocs\...
Not sure what the extra step is that I need to perform in order to store the data correctly.
Many thanks!
Noel
1 Answer
According to this ticket:
Cannot serialize object wrapping 3rd party library structs. Must
serialize the xml (to a string) and store that to session and reload the
xml when restoring from session
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.