Home › Forums › General Issues › Large amount of custom fields › Reply To: Large amount of custom fields
I had the same issue and solved it this way:
when I save my post wp generates a serialized array and saves it to post_meta
function update_vol( $post_id ) {
if (get_post_type($post_id)=='volumes'){ //check for my custom post type with tons of data
$post = get_post($post_id);
setup_postdata($post);
$fields = get_fields();
$field_values = array();
if( $fields )
foreach( $fields as $field_name => $value ){
if (!is_object($value)) // checking for value is not an post object
$field_values[$field_name]=$value; // storing data to array
}
$field_values_fordb = serialize($field_values); //serializing our array
$add_check = add_post_meta($post_id,'serialized_',$field_values_fordb,true); //trying to store our values to db using ADD method
if (!$add_check) update_post_meta($post_id,'serialized_',$field_values_fordb); //if ADD method failed trying UPDATE method
}
wp_reset_postdata()
}
add_action( 'save_post', 'update_vol' );
so at front-end I work only with one meta field ‘serialized_’
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.