In a case where a post have a few dozen custom fields and I just need two or three, in term of performance and optimisation, is it better to do one request getting every fields with
or multiple requests getting a single field with
and if it depends (on the post’s total number of fields, the number of fields needed, etc), at which point does one solution become better than the other ?
Each time you use get_field(), you create a new query to the database. So, generally speaking, it would be a good idea to use get_fields() first, to cache all the results, then get_field() where needed.
For example:
Still, if you have lots of fields, with large data in them, and you only need two of them, it might be better to just use get_field() twice, instead of increasing the load of the DB server and filling the cache with useless data.