I make a request to my custom endpoint function in functions.php :
add_action( 'rest_api_init', function () {
register_rest_route( 'wp/v2', '/homepage/', array(
'methods' => 'GET',
'callback' => 'custom',
) );
} );
And in return I get an array of posts of an author id :
function custom( $data ) {
$posts = get_posts( array(
'author' => $data['17'],
) );
if ( empty( $posts ) ) {
return null;
}
return $posts;
}
I want to return all posts and all categories but I get an error :
return [$posts , $categories ];
How can I get All posts and all categories in a single array inside custom function ?
2
Answers
Ok try this
You do all of that like this :