问题描述
我正在创建名为console.log(playerList.itemAt(i).playerName)
的自定义帖子类型。
我需要更改一些内容,例如第一次获取缩略图而不是获取ID等。我似乎找不到像平常一样添加过滤器的方法,尝试过,但是case-studies
似乎不起作用。
这是代码:
add_filter
解决方法
WP会产生所有的拇指吗?我认为您不需要更改声明CPT的方式。但在视图上,请使用:
for content in data["content"]:
content["value"]
您应该使用wordpress的内置功能调用图片,只需将大小作为第二个参数传递即可。
,我相信 register_rest_field
函数正是您要找的。调用 rest_api_init
钩子。它允许您通过 REST API 返回自定义数据,但请注意不要弄乱其他插件或您的 UI 可能依赖的现有字段。
add_action('rest_api_init',function () {
register_rest_field(
<your post type,'case-studies'>,<name you want the new data to appear under>,array(
'get_callback' => function (array $post_object) {
... do your logic here
return whatever you want to be shown in the REST API
})
);
});