SQL to Change User Level in WordPress

Published: 3 Mar 2023

This page explains how to change user level with a SQL query directly in the WordPress database.

What is user level and what it does

Although user levels have been oficially deprecated since WordPress 3.0, they are still supported for back compatibility and may still have a meaning in some WordPress themes or plugins.

Generally, user level is a number from 0 to 10, which decides how much a user can do in WordPress admin.

For instance, level 1 can create draft posts only, level 2 can write and publish posts, level 4 can also manage categories and moderate comments, and level 10 can do everything.

A higher level can always do everything that lower levels do, plus some more. Levels 5 and up can also manage other users. For full specifications, see the official documentation.

For new code, user hierrarchy has been handled by Roles and Capabilities.

How user level is stored in WordPress database

User level is not stored directly in the wp_users table. Instead, it is one of user meta records, which are stored in wp_usermeta.

In this table, each meta record has its own row, so there are multiple rows for each user. To find the correct meta value, we need to specify two things in the SQL query WHERE clause:

  • user ID number (the column user_id)
  • usermeta key (the column meta_key)

SQL to change user level for given user ID

The following SQL query changes user level to 10 for the user with ID = 123:

UPDATE `wp_usermeta`
SET `meta_value` = 10
WHERE `meta_key` = 'wp_user_level'
AND `user_id` = 123;

How the SQL changes with different table prefix

The above example assumes the default WordPress database table prefix wp_.

If your database uses a different table prefix, you need to change the query in two places: Not only the wp_usermeta table name, but also the value of the meta_key column in the WHERE clause (wp_user_level), because user level (and several other usermeta records) have the table prefix prepended to their meta_key.

For example, if your table prefix is blog_, the query will look like this:

UPDATE `blog_usermeta`
SET `meta_value` = 10
WHERE `meta_key` = 'blog_user_level'
AND `user_id` = 123;

By remaining on this website or using its content, you confirm that you have read and agree with the Terms of Use Agreement.

We are not liable for any damages resulting from using this website. Any information may be inaccurate or incomplete. See full Limitation of Liability.

Content may include affiliate links, which means we may earn commission if you buy on the linked website. See full Affiliate and Referral Disclosure.

We use cookies and similar technology to improve user experience and analyze traffic. See full Cookie Policy.

See also Privacy Policy on how we collect and handle user data.

© 2024 WPDir