I'm trying to create my own user profile pages. When someone requests
example.com/profile/username, I want to query the user tables for a user with
username (= slug) and display the result.
Ideally, I would alter the main query to query only the user tables and return this result. This does not seem to be possible (
WP_User_Query are totally separate). Correct?
I do not want to:
- redirect to a page or anything else
- hack my templates
- insert a post/page for each user
- install any plugins
It seems the only way to avoid redirects and let my templates work for real 404's is with an action hook at
parse_query that sets
false when my profile route is matched (via
To avoid hacking my templates, I'd like to perform my user query ASAP and add the result to the main query. I am thinking of performing my user query and simply turning the result into a post on the fly and letting that be the sole result of the main query. This seems the cleanest way to work views into Wordpress. However, I do not want to insert this post into my tables.
Can I create a post and pass it to a template as a main query result without saving it elsewhere, or would I need to insert and then delete it? Will waiting until
parse_query cause problems?
Is there a better way?