I’m tring to add a custom endpoint for a page subpages.
Parent Page ID = 151
function list_subpages( $data ) {
$subpages = get_pages( array(
'child_of' => $data['151'],
) );
if ( empty( $subpages ) ) {
return null;
}
return $subpages;
}
add_action('rest_api_init', function () {
$version = '2';
$namespace="wp/v" . $version;
$base="subpagelist";
register_rest_route($namespace, "https://wordpress.stackexchange.com/" . $base, array(
'methods' => 'GET',
'callback' => array($this, 'list_subpages'),
));
});
Getting status 500 error..
How can I fix it?