I am trying to build custom user profile with the guidance of this tutorial: How to make a WordPress profile page
I have successfully implemented it to my theme, everything is working well.
Now what I want to achieve is to get the comment template in the user profile page, where other registered user can post comment on his profile page, kinda like facebook wall or last.fm shoutbox.
I am trying it like this:
In the author page I am added this line:
<?php comments_template(); ?>
But it does not show up.
Then I tried this way: Get WordPress comments outside of WordPress
It adds the comment template alright but, does not work. When you click on on the submit button it redirects to a blank page.
I think the goal is not achievable easily, it requires custom database creation for each user to store the comments, since the comment system only stores comments of certain page or post, not for any other page like archive or author page.
If anyone can show me the right direction, I will be forever grateful.
Thanks
Towfiq I.
Hi @Towfiq:
Comments are related in the database to Posts. You’ll have to do a lot of work to get Comments to relate to Users.
Have you considered creating a Custom Post Type for Users and then use either a
user_meta
field to store thepost_id
, or apostmeta
field to store theuser_id
, or both? If you did that then you would get the comments with no effort at all.UPDATE
What follows is code developed after our discussion in the comments.
I’ve been meaning to write something like this for a long time but your question finding got me to make it a priority. I’ve created a
'towfiq-person'
custom post type for you and I’ve set it up to automatically add a Person post whenever a User is added and it uses the email address as the associating key in a post custom field called'_email'
.It also associates a User with an appropriate email address to the Person post if a User is added or updated with the same email as an existing Person (this may or may not be a good idea.) And it cross-references User with Person and Person with User using postmeta and usermeta fields
'_user_id'
and'_person_id'
, respectively.These are of course business rules I chose to implement but they may turn out not to be appropriate for your use-case in which case you may need to modify them. You also may find ways that WordPress allows these two to get out of sync but it’s hard to know that without exhaustive testing. If you find issues you can always look to update the logic to resolve them.
You can copy the following code to your theme’s
functions.php
file:If you need any clarifications to what I did and why, just ask in the comments.
Just add a custom post type loop inside author.php and use that custom post’s comment form. I’ve done it many times and it works great.
https://github.com/pjeaje/code-snippets/blob/gh-pages/GP%20author.php%20with%20multiple%20loops