How to get home page?
How to get home page using path() not an id() filter?
wp.pages().id(2).... works well wp.pages().path('/').... said wp.pages(...).path is not a function
This looks like a bad documentation issue on our end; path is not listed in the accepted parameters for the core pages endpoint, which suggests that it was removed before we merged the REST API and I did not notice to update the documentation here. Thank you for reporting the issue, we'll validate this is no longer supported and update the documentation.
Unfortunately there is no obvious way I can think of to accomplish what you want. The best I could suggest would be to .search() for the title of the homepage, or use .slug() if you know the slug for the page.
You can register custom endpoint and get the homepage from there. See the code they used for wuxt:
add_action('rest_api_init', 'wuxt_front_page_route');
function wuxt_front_page_route() {
register_rest_route('wuxt', '/v1/front-page', array(
'methods' => 'GET',
'callback' => 'wuxt_get_front_page'
));
}
function wuxt_get_front_page( $object ) {
$request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
$frontpage_id = get_option( 'page_on_front' );
if ( $frontpage_id ) {
$request = new WP_REST_Request( 'GET', '/wp/v2/pages/' . $frontpage_id );
}
$response = rest_do_request( $request );
if ($response->is_error()) {
return new WP_Error( 'wuxt_request_error', __( 'Request Error' ), array( 'status' => 500 ) );
}
$embed = $object->get_param( '_embed' ) !== NULL;
$data = rest_get_server()->response_to_data( $response, $embed );
return $data;
}
Then you can get the homepage by calling WPAPIInstance.namespace('wuxt/v1').homepage()
I hope it helps
Thank you for the example! @panayotoff would you be comfortable with me adding this snippet to the docs as a FAQ item guide?