A scenario I keep coming across is where an organisation might have several staff for whom I want to have some sort of listing and a single profile page with biographical information.
Typically I would create a custom post type for staff and maybe a custom taxonomy if needed.
But now I’m wondering if it might not be optimal to use the built-in “user” post type in WordPress. I realise I can customise the user profile fields, display user listings, single profiles etc Custom taxonomies are possible too I believe.
Is there a best practice here?
I have a case now where all staff are also writing blog posts under their own name and so have a user account anyway and it crossed my mind that maybe I’m better off just fleshing out their user profiles and working with author.php instead of using the custom post type of ‘staff’.
For now I’ve been going with the CPT and using Posts 2 Posts plugin to associate their “staff” post with their “user” account and thereby create listings of their blog posts on their single staff page.
Any thoughts on how best to implement this in wordpress is appreciated.
If people you want to show publicly on a site are users, i.e. have an account and write posts, in my opinion it’s much better to use the WordPress user functionality: all the information you would put in a CPT can also be put in user metadata, and creating users is mandatory (they have to login), while creating a CPT can be avoided and, for me, is redundant.
However, I know that using a CPT can be simpler, for some reasons:
author.php
is not a profile page.WP_User_Query
to do this, but isolating staff from users that must be hidden can be a little hard: there is no user taxonomy and using user roles can generate problems if you want to assign the public role to any user that must not be publicly visible.Luckily these problems are not real problems and can be solved easily. The workflow I suggest is:
example.com/staff
will call a page (the one you assign the template created on 3.) and a URL likeexample.com/staff/user/nickname
will call the same page, but pass the query varuser
with valuenickname
that you can use in the page to show the user profile.1., 2. and 4. can be easily done in a plugin. I will give you the bones of this plugin, that should be improved:
The plugin does exactly what I said. Regarding adding custom fields for user profiles, as an example, I added just 3 fields. One of them is intended to be used for a user image and accepts the ID of an attachment. Of course in the real world it’s better to call the media uploader and let the user choose to upload an image, but this is not in the scope of this answer…
After the plugin is saved and activated, we have to create the page template, create a page, and assign that template. Again, I will post here a proof of concept for the template:
Now create a page and assign this template. Then assign the user role ‘staff’ to your staff and fill the profiles.
As a final touch, in your
author.php
you can add, probably in the header, something like this:That’s all. Test it, improve it and have fun with it.