I use ACF to allow users to create custom posts (listings) from the front-end. Users can also browse all listings to connect with other users.
I’ve built a custom loop that goes through the listings and displays a box showing the details for each one of them.
The loop basically goes through something like this:
<h1><?php the_field('title') ?></h1>
<small><?php the_field('category') ?></small>
<p><?php the_field('description') ?></p>
<p><?php the_field('condition') ?></p>
...
I’m worried that this is a horribly inefficient way of loading the fields. At ~10 fields per post, displaying 32 posts would mean 320 extra requests that could possible be reduced to 32.
Hi.
I have a better solution, I think. I’m using ACF+Custom Content Shortcode.
Very simple. And I love it so much!!!!
The first time that you call the_field(), all of the custom field data for the post should be retrieved from the database and stored in the WP cache. Subsequent calls the the_field() get values from this cache. At least that’s the way it’s supposed to work.
You can test this by installing this plugin https://wordpress.org/plugins/query-monitor/
load your page and see how many queries are done. Then add this directly before your calls the_field();
$meta = get_post_meta();
This specifically tells WP to get all custom fields for a post. When you load your page again there should be no difference in the number of queries.