最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Rest API Wordpress : filter acf fields with arrays and getEntityRecords - Stack Overflow

programmeradmin3浏览0评论

i'm trying to filter through acf fields in wordpress Blocks. I have a couple of select components fetching all my posts and filtering them based on their acf fields. It's working pretty well except for one field. It's a relation one in ACF and it generate an array. In my REST route, for every post, i did see it like that :

"acf": {
      "api_id": "31",
      "capacity": "30",
      "api_array": [1795]
    }
I expose my fields like this in my php :
add_filter( 'rest_rooms_query', function( $args, $request ){
  if ( $meta_key = $request->get_param( 'metaKey' ) ) {
     $args['meta_key'] = $meta_key;
      $args['meta_value'] = $request->get_param( 'metaValue' );
  }
  return $args;
}, 10, 2 );

In my block.json, i'm totally able to ask a query like that :

"attributes": {     
        "query": {
            "type": "object",
            "default": {
                "perPage": -1,
                "postType": "rooms",
                "metaKey": "capacity",
                "metaValue": "30"
            }
        }
    },

And it's working just fine (in my edit.js i'm able to update all of it with my select values). But when it comes to do the same for my "api_array" field, nothing works! So if i try this, there's no way to make it work (i tried all the syntax possible for arrays, nothing is able to make it work) :

"attributes": {     
        "query": {
            "type": "object",
            "default": {
                "perPage": -1,
                "postType": "rooms",
                "metaKey": "api_array",
                "metaValue": [1795]
            }
        }
    },

Did anybody have a clue of what's going on for this field?

Thanks a lot!

发布评论

评论列表(0)

  1. 暂无评论