Support

Account

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_’