我们可以使用rest_prepare删除wordpress rest api中的一些内容吗?

问题描述

我使用rest_prepare编写了一些自定义过滤器来格式化wordpress中的rest响应,我需要提供一些额外的逻辑来隐藏基于此的内容。但它返回 null 而不是 empty 对象。我们如何做到这一点?

function prepare_promobanner($data,$post,$request) {
  if ($data->data['customfields']=="someconditions")
    return [
        'id' => $data->data['id'],'title' => $data->data['title']['rendered'],'customfields' => $data->data['customfields']
    ];
}
}
add_filter('rest_prepare_promobanner','prepare_promobanner',10,3);

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)