Complete the code to get a query parameter named 'id' from the URL in WordPress.
$id = get_query_var('[1]');
In WordPress, get_query_var('id') retrieves the 'id' parameter from the URL query.
Complete the code to send a JSON response with status 200 in WordPress.
wp_send_json_success([1]);wp_send_json_success() expects an array or object to send as JSON data.
Fix the error in the code to check if a POST request contains a 'name' parameter.
if (isset($_POST['[1]'])) { $name = sanitize_text_field($_POST['name']); }
The isset check must match the key used to get the value from $_POST.
Fill both blanks to create a REST API endpoint callback that returns a JSON response with a message.
function my_api_callback() {
return wp_send_json_[1](array('message' => '[2]'));
}Use wp_send_json_success to send a success response with a message.
Fill all three blanks to register a REST API route that accepts GET requests and uses a callback.
add_action('rest_api_init', function () { register_rest_route('myplugin/v1', '/data', array( 'methods' => [1], 'callback' => [2], 'permission_callback' => [3] )); });
The route uses GET method, the callback function name, and a permission callback that always returns true.