Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to get the default REST API base URL in WordPress.
Wordpress
const apiBase = wpApiSettings.[1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'endpoint' or 'url' instead of 'root'.
Trying to access a property that does not exist.
✗ Incorrect
The default REST API base URL is stored in wpApiSettings.root.
2fill in blank
mediumComplete the code to fetch posts from the default WordPress REST API endpoint.
Wordpress
fetch(wpApiSettings.root + 'wp/v2/[1]')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'page' instead of 'pages'.
Using 'users' or 'comments' which are different endpoints.
✗ Incorrect
The default endpoint to get posts is wp/v2/posts.
3fill in blank
hardFix the error in the code to get a single post by ID from the WordPress REST API.
Wordpress
fetch(wpApiSettings.root + 'wp/v2/posts/[1]')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name instead of an actual ID.
Using ':id' which is not valid in this context.
✗ Incorrect
You must replace the placeholder with an actual post ID number, like 123.
4fill in blank
hardFill both blanks to create a URL to fetch comments for a specific post ID.
Wordpress
const url = wpApiSettings.root + 'wp/v2/[1]/[2]/comments';
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'pages' instead of 'posts' for comments.
Using an invalid post ID.
✗ Incorrect
To get comments for a post, use 'posts' and the post ID like '123'.
5fill in blank
hardFill all three blanks to build a URL to update a post with ID 789 using the REST API.
Wordpress
fetch(wpApiSettings.root + 'wp/v2/[1]/[2]', { method: '[3]' })
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'GET' method instead of 'PUT' for updating.
Using wrong content type or post ID.
✗ Incorrect
To update a post, use 'posts' as the type, the post ID '789', and the HTTP method 'PUT'.