Answers for "rest api response 404 wordpress"

PHP
0

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
    }
}
Posted by: Guest on May-25-2020

Browse Popular Code Answers by Language