I have a unique project that I am trying to prototype where some of a page’s assets comes from wordpress, whereas others come in from a request to a remote API.
Currently I use a page called “series” that uses this structure to make a wp_get_remote call to pass data into the page:
site_url/series/?pname=xyz
And would like to change it to be pretty:
site_url/series/xyz
So the effect would be the series page is called, and then my request runs to call in the data I need from the endpoint. I need to run this as soon as possible, because the endpoint has data that I would like to set to the meta description, plus the majority of the page content relies on the data I retrieve.
I have been trying to use the hook ‘parse_request’, but I get a Warning: Cannot modify header information headers already sent by .. pluggable.php
add_action( 'parse_request', 'test_changes' );
function test_changes( $query ) {
$request_uri_string = $_SERVER['REQUEST_URI'];
echo $request_uri_string;
echo "<br>";
if( strpos($request_uri_string, 'series') !== false ){
echo "theres a series here";
unset($query->query_vars);
$query->query_vars[ 'pagename' ] = "series";
$query->query_vars[ 'page' ] = "";
$query->request = "series";
$query->matched_query = "pagename=series&page=";
}
//See what is returned.
echo "<br><br><p>Parse Request</p>";
var_dump($query);
return $query;
}
Trying to get some insight into why this doesn’t work, solutions to create the result I want, and perhaps some other ways you can use ‘parse_request’.