Skip to content

Commit

Permalink
posts接口支持自定义字段获取
Browse files Browse the repository at this point in the history
之前默认就是获取全部字段的,但读取方式比较局限,本次优化了对任意字段值读取的方式
  • Loading branch information
jrotty authored Feb 28, 2023
1 parent b736d15 commit bdd9f6f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion JSON/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ private function posts() {
->join('table.relationships', 'table.metas.mid = table.relationships.mid', Typecho_DB::LEFT_JOIN)
->where('table.relationships.cid = ?', $post['cid'])
->where('table.metas.type = ?', 'tag'));
$post['thumb'] = $this->db->fetchAll($this->db->select('str_value')->from('table.fields')->where('cid = ?', $post['cid']))?$this->db->fetchAll($this->db->select('str_value')->from('table.fields')->where('cid = ?', $post['cid'])):array(array("str_value"=>"https://ww4.sinaimg.cn/large/a15b4afegw1f8sqaz6y6bj20go06j0u2"));
$fields=$this->db->fetchAll($this->db->select('name','str_value')->from('table.fields')->where('cid = ?', $post['cid']))?$this->db->fetchAll($this->db->select('name','str_value')->from('table.fields')->where('cid = ?', $post['cid'])):array(array("name"=>"null","str_value"=>"https://i0.hdslb.com/bfs/article/a2ae2ed735a899ff319a6112c8de60512ad04d11.jpg@942w_590h_progressive.jpg"));
foreach($fields as $field) {
$newfields[$field['name']]=$field['str_value'];
}
$post['fields'] = $newfields;
$result[] = $post;
}
$this->export($result);
Expand Down

0 comments on commit bdd9f6f

Please sign in to comment.