Home › Forums › General Issues › ACF Performance
I am using ACF to load in custom options for product pages within WooCommerce. I am using this technique (http://www.advancedcustomfields.com/resources/dynamically-populate-a-select-fields-choices/) to dynamically load in options from the Options page onto the product page as checkboxes for the client to check/uncheck which options to show. The product pages have become incredibly slow though (30+ seconds to load the page) (see example here: http://quakercomm.wpengine.com/product/k200-slider). Any ideas on how I can improve the performance? I can not tell if the issue is there are too many options the client has added to the Options page or if my technique for dynamically pulling in the data just doesn’t scale to the number of options the client needs.
A sample of the code I am using to dynamically generate the options is below. I have about 15 of these snippets, each for a different section of options:
function ap_options_handles( $field ) {
// reset choices
$field['choices'] = array();
// load repeater from the options page
if(get_field('ha_options', 'option')) {
// loop through the repeater and use the sub fields "value" and "label"
while(has_sub_field('ha_options', 'option')) {
$value = get_sub_field('ha_value');
if( 0 == $value ) $value = 'zero';
$label = get_sub_field('ha_label');
$field['choices'][ $value ] = $label;
}
}
return $field;
}
add_filter('acf/load_field/name=handles', 'ap_options_handles');
On the template side, I have the following code for each section to output the options:
// HANDLES
$ha_options = get_post_meta( get_the_ID(), 'handles', true );
//Loop through the options, displaying relevant content
foreach( $ha_options as $option ) {
if( have_rows('ha_options', 'options') ):
while ( have_rows('ha_options', 'options') ) : the_row();
$value = get_sub_field('ha_value','options');
if( 0 == $value ) $value = 'zero';
$handlesImage = get_sub_field('ha_image','options');
if ($value == $option) {
echo '<div class="center col-md-3 col-sm-4"><img src="';
echo $handlesImage['url'];
echo '" alt="';
echo $handlesImage['alt'];
echo '"><p>';
the_sub_field('ha_name','options');
echo '</p></div>';
}
endwhile;
else :
// no rows found
endif;
}
I have provided you a login for the site if you would like to go in and take a look. The login info is below:
http://quakercomm.wpengine.com/wp-login.php
user: acf
password: send in email
Hi,
PS: It is not advisable to share your login credentials on the public forum.
In order to establish the cause for the slow loading, try deactivating all the other plugins and see if the problem persists.
Please note the latest version of acf comes an easy way to cache fields using local-json which assist in improving site performance.
http://www.advancedcustomfields.com/resources/local-json/
The topic ‘ACF Performance’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.