Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

WordPress

ben pines
ben pines
8,389 Points

Where in the wordpress database should I place a timeline of dates and data?

I am trying to create a timeline of a user's weight. Where in the wordpress database should I store this? in a new table? in an object? in the usermeta?

1 Answer

Rich Inman
Rich Inman
2,173 Points

I think that the best place for this would be in a custom table. You're going to have to set up a one to many relationship for this and I just don't think doing it with user meta would be very efficient.

Just create a new table with a user_id column that you can use to reference.

When you create the list you can then just query like this:

SELECT * FROM user_weights WHERE current_user_id = user_id ORDER BY desc;

This should give you every record in the table that's associated with that user sorted by most recent entries. It will all come in as an associative array if you use the most up to date php syntax for the query so it should be easy to parse.

Obviously use your own names for the tables and variables, but you get the idea.

Trying to pull in user meta would be a more difficult task I think. I hope this was a clear response, and if you decide to go this route and need some php examples of how I've done this before I'd be more than happy to provide them.