Replies: 0
I want to allow my search.php to return JSON, so that I can use Relevanssi with my JS application.
However, I get a headers already sent error when trying to do this because Relevanssi sets this already?
The odd thing is, I use this script on an older site with no problems. It fails however with the latest standard Relevanssi version 3.5.11 (and latest WordPress).
<?php
header('Content-Type: application/json');
$results = array();
if (have_posts()):
while (have_posts()):
the_post();
$results[] = array(
'permalink' => get_permalink(),
'title' => get_the_title()
);
endwhile;
endif;
echo json_encode($results);
die();
?>
Is there any way to get this to work, or perhaps a better way to do this somehow? I can’t find any information on the matter.
Not sure if this is a bug or not. The exact error is:
Warning: Cannot modify header information – headers already sent by (output started at /Applications/MAMP/htdocs/NBC/wp-content/plugins/relevanssi/lib/search.php:554)
I also wrote this up in a post on StackOverflow if this helps?
https://stackoverflow.com/questions/44931264/how-to-output-json-for-wordpress-search-page-using-relevanssi
Many thanks!
- This topic was modified 13 minutes ago by michaelpumo.