Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

rest api response 404 wordpress

// if there is no posts return 404 with custom message
if( empty($query->posts) ){
	return new WP_Error( 'no_posts', __('No post found'), array( 'status' => 404 ) ); // status can be changed to any number
}

// output
{
	"code": "no_posts",
	"message": "No post found",
	"data": {
		"status": 404
    }
}
 
PREVIOUS NEXT
Tagged: #rest #api #response #wordpress
ADD COMMENT
Topic
Name
7+6 =