📜  rest api 响应 404 wordpress - PHP 代码示例

📅  最后修改于: 2022-03-11 14:54:19.151000             🧑  作者: Mango

代码示例1
// 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
    }
}