Where to Store Custom User Fields

I know this question is very old, but I wanted to share my experience with working with large databases and storing custom user data.

Basically wp_usermeta is the default and easiest option to store user meta and it works really well for smaller databases, where you might want to store a few extra fields for your users.

But if you have a large number of users and you need to store many fields and especially if you need to generate reports, you might want to avoid wp_usermeta and create a custom database table for your data where each field is stored in a separate column.

wp_usermeta becomes really slow to read with large number of records, especially if you need to generate reports for a high number of users in one query containing a high number of fields – in that case you would have to write an additional join for each field. The other disadvantage of using wp_usermeta is that all values are stored as strings, so you would need to cast them to the corresponding data types when reading/searching/sorting the data.

Using a custom table where each field is stored in a separate column has the following advantages:

  • Increased performance
  • You can define each column type and constraints, in this way it will be a lot less likely to store bad data. Also, you won’t need to cast the values when reading
  • You can add custom indexes to further increase performance of frequent queries

It’s also worth mentioning that using a custom table is more complex to implement – you need someone experienced with databases to design the table and also you’ll have to write all your read/write SQL queries manually (though $wpdb provides easy to use methods for that).

In the end there’s no one size fits all solution – the best way to help you decide which approach is better for your project is to create some simple prototypes of the two approaches and benchmark the queries that you are planning to use.

Leave a Comment