Home Forums General Issues Large amount of custom fields


Large amount of custom fields

  • Hello Everyone

    I’m working on a site that has products with a large number of custom fields (20-40 per product) using Advanced Custom Fields Pro. There are 3 languages and every language has around 1000 products. Every custom field generates two or more queries when showing data with get_field().

    I am also using WPML plugin for translations which generates a lot of queries.

    Everything works fine so far when page caching is on (W3 Total cache), but I’m worried about performance in the future.

    Is there a way to store custom fields easily in a custom table or as serialized object in wp_postmeta? Or is there a smarter way?

    Thank You!

  • 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);
      $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
    add_action( 'save_post', 'update_vol' );

    so at front-end I work only with one meta field ‘serialized_’

  • Great – thanks for prompt response! This could be a solution.

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

The topic ‘Large amount of custom fields’ is closed to new replies.