• This forum has been archived. New threads and replies may not be made. All add-ons/resources that are active should be migrated to the Resource Manager. See this thread for more information.

How to rebuild the custom field cache

Rigel Kentaurus

Well-known member
All the custom fields for the users are stored in a couple of places.
  1. The first one is the database table xf_user_field_value in which it maintains a relation between the field_id and the user_id
  2. The second one is a php serialized version of it, that is stored inside custom_fields in the xf_user_profile table
If you were to code an addon that writes to a custom field, you would need to keep updating both the table and the serialized version. Using a custom field might be a good idea since there are already hooks in the system for it, and should it need to be editable there is all the functionality already coded in for making it appear in Personal Information or Preferences.

This value is recalculated when the user edits his information and clicks on "save". Another way is when you go to the Maintenance tasks in the AdminCP and "Rebuild user information"

In some cases, you might not want to rebuild all user information as that would also do posts, and any other information associated to the user. If you wanted to only rebuild the custom fields, a simple PHP file with the following code will suffice.


$startTime = microtime(true);


XenForo_Application::set('page_start_time', $startTime);

$db = XenForo_Application::getDb();
$userIds = $db->fetchCol("SELECT user_id FROM xf_user");

$model = new XenForo_Model_User();
foreach ($userIds as $id)
    print "Rebuilding $id<br/>\r\n";