I’ve read through all the documentation and watched all the videos on the YT channel, but can’t seem to find an answer to my issue.
I’m setting up a custom looper to display data from an external REST API. I have the following filter written to fetch the data:
add_filter( 'cs_looper_custom_get_publications', function( $result ) {
$apiUrl = "https://example.com/rest-api/publications/";
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Token 123456789', 'Accept: application/json'));
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $apiUrl);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response);
$results = $data->results;
$json_results = json_encode($results);
return $json_results;
});
Which works, grabs all my data just fine. $json_results looks like this:
[
{
"id": 14372,
"headline": "Sample",
"tags": [],
"categories": [],
"publish": true
},
{
"id": 14372,
"headline": "Demo",
"tags": [],
"categories": [],
"publish": true
},
{
"id": 14372,
"headline": "Test",
"tags": [],
"categories": [],
"publish": true
}
]
And I have the provider/consumer set up:
But the looper doesn’t output anything. I can paste the same block of JSON into a looper and it works fine:
What am I doing wrong here? Is there some documentation somewhere I should be looking at? Thanks in advance!