How can I send api calls from my plugin?

You can check this: $api_endpoint=”https://url_to_API”; $api_args = array( ‘method’ => ‘GET’, ‘headers’ => array( ‘Accept’ => ‘application/json’, ‘any’ => ‘other’ ) ); $queries = array( ‘your_query’ => 1, ‘another_query’ => 5, ); $api_endpoint = add_query_arg( $queries, $api_endpoint ); $response = wp_remote_request( $api_endpoint, $api_args ); $response_code = wp_remote_retrieve_response_code( $response ) $data = json_decode( wp_remote_retrieve_body( $response ), … Read more

Get Menu Items from REST API (React)

getMenu() fetches data from the GET /wp/v2/menus/<id> endpoint, whereas getMenuItem() fetches data from the GET /wp/v2/menu-items/<id> endpoint, but they have the same usage syntax, where you just need to pass the ID of a menu or menu item. As for getMenuItems() and another function you can use — getMenus(), the endpoints are GET /wp/v2/menu-items (for … Read more

WP Rest API feature image breaking react component

Resolved! If no feature image exists, then _embedded[‘wp:featuredmedia’] is not used. To resolve, the prop value needs to be wrapped into a conditional. <Post key={post?.id} id={post?.id} title = {post?.title.rendered} link = {post?.link} img = {post && post._embedded && post._embedded[‘wp:featuredmedia’] ? post._embedded[‘wp:featuredmedia’][0].source_url : ‘ ‘ } category = {post?.categories} />