if ($_GET[\'api\'] == \'json\' && isset($_GET[\'id\'])) {
$post = get_post($_GET[\'id\']); // $post contains the post object
header("content-type: application/json");
echo json_encode($post);
}
die();
这段代码可以工作,但是如果我想扩展它,那么在第二种情况下(下面),如果我写
?second=case&id=204
到我获取的url
Unexpected
但如果我写信
?first=case&id=204
我收到了请求
if (isset($_GET[\'api\'])) {
if ($_GET[\'first\'] == \'case\' && isset($_GET[\'id\'])) {
// $query is the WP_Query Object
$post = get_post($_GET[\'id\']); // $post contains the post object
header("content-type: application/json");
echo json_encode($post);
}
if ($_GET[\'second\'] == \'case\' && isset($_GET[\'id\'])) {
// $query is the WP_Query Object
$post = get_post($_GET[\'id\']); // $post contains the post object
header("content-type: application/json");
echo json_encode($post);
}
die();
}