dongqiaozhe5070 2018-10-12 20:35
浏览 117

Wordpress Rest:ACF到REST API过滤器致命错误

Developing an application using wordpress rest api for the backend.

I'm working with the following plugins:

Advanced Custom Fields PRO 5.5.14 ACF to REST API 3.10 Better REST API Featured Images 1.2.1 Custom Post Type UI 1.5.8

Result of endpoint wp-json / wp / v2 / games without filter:

enter image description here

I would like to filter post of type "games" by datas_plataforma.plataforma.slug

Something like:

  wp-json / wp / v2 / games? plataform-slug = {slug}

For this I tried the following filter in functions.php:

add_filter( 'acf/rest_api/games/get_fields', function( $data, $request, $response ) {
if ( $response instanceof WP_REST_Response ) {
    $data = $response->get_data();
}

if( isset( $data['acf']['datas_plataforma']['plataforma']['slug'] ) ) {
    $data['acf']['datas_plataforma']['plataforma']->acf = get_fields( $data['datas_plataforma']['plataforma']->SLUG );
}

return $data;

}, 10, 3);

But when I access the endopoint wp-json / wp / v2 / games I get error 500.

Update:

Fatal error: Uncaught ArgumentCountError: Too few arguments to function {closure}(), 2 passed in /opt/bitnami/apache2/htdocs/service/wp-includes/class-wp-hook.php on line 286 and exactly 3 expected in /opt/bitnami/apache2/htdocs/service/wp-content/themes/twentyseventeen/functions.php:657

Some help?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!
    • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?