Home Forums ACF PRO Can ACF return all fields with a custom query?


Can ACF return all fields with a custom query?

  • I’m working on a project that creates a map from posts of a custom post type called “Church”. So, we’re pulling all the church posts along with their ACF fields (latitude, longitude, etc.)

    My question is, is it possible to grab all of that data with the original query somehow, rather than having to use get_field() or the_field() each time?

    The goal is to cut down the number of requests to the server, and using get_fields() isn’t helpful either because we don’t need all the other ACF data that pulls in.

    Is there any way to get all the fields with the original query?

  • There are two choices that you can do that will cut down on the number of db requests.

    In ACF you can use get_fields(), will return all of the acf fields This will return all of the fields properly formatted by ACF.

    If you don’t care about having ACF format the values, would depend on what the field types are, in straight WP you can use get_post_meta($post_id) using this function without a specific meta_key will cause WP to get all post meta values in one query and put them into a cache.

    You can then use get_field() and the_field() if you want and these functions will not cause a new CB query because all of the meta values will be cached.

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Can ACF return all fields with a custom query?’ is closed to new replies.