REST API custom endpoint to fetch pages and posts not working

First off, there’s a default endpoint for retrieving pages, but I presumed that you intentionally did not use it? Now the issues with your code: That $request->get_params() gets all the parameters and not a single one. So for single parameters, you should use $request->get_param(). $slug = $request->get_params(‘slug’); // incorrect $slug = $request->get_param( ‘slug’ ); // … Read more