I’ve ensured that the Representative role has read/edit/create/publish
post capabilities
Okay, that’s good.
But did you also assign the level_<number>
capability to the role, where the <number>
is at least 1
? If not, then at least the users in the role need to be manually assigned the level 1
or a greater level (2
, 3
, etc.).
And the reason is because the Author dropdown on the post editing screen will only include users having a level of at least 1
and the level is stored in a user metadata named wp_user_level
in a non-Multisite install.
More specifically, the Author dropdown uses wp_dropdown_users()
(if your post type uses the old/classic editor) or the GET /wp/v2/users
endpoint in the REST API (if your post type uses Gutenberg, i.e. enabled in the REST API) with the who
argument set to authors
which then includes only those users having a user level of 1
or above. (see source on Trac)
So please ensure that the Representative role has the proper user level capability so that new users will automatically have the above metadata set to the correct value.
For existing users in that role, you could programmatically update their wp_user_level
metadata (using update_user_meta()
), or you could use a raw SQL to update that metadata, or if you have WP-CLI installed on your site, then you could easily update individual users using the wp user meta update
command like so: wp user meta update 123 wp_user_level 1
(where 123
is the user ID).
UPDATE
In reply to your comment:
The meta field I created before was
wp_user_level
inside of the
usermeta table. However, this meta key has to include the WP table’s
prefix. So, if your wp table prefix iswp_12
(meaning, your usermeta
table is namedwp_12_usermeta
), then thewp_user_level
meta key
must also have the prefix. So, once I setwp_12_user_level
to1
,
it worked!
Yes, that is correct and sorry for not clarifying about the prefix.. 🙂
So the user level meta is named following this format: <blog prefix>user_level
, where the blog prefix is in the form of <base prefix><site ID>_
or just <base prefix>
(see the Multisite note in the next paragraph), and the base prefix defaults to the WordPress table prefix ($wpdb->prefix
), e.g. wp_12_
in your case (note that the prefix includes the last _
).
Therefore in a stock WordPress install where the table prefix defaults to wp_
, the user level meta would be named wp_user_level
; however, if Multisite was enabled, then the name (meta key) would be wp_2_user_level
if the ID of the current (sub-)site is 2
. The main site, though, always uses the format <table/base prefix>user_level
, i.e. without the <site ID>_
part.