Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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.