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

Adam Duffield
Adam Duffield
30,494 Points

Inputting custom values into Wordpress DB? Any WordPress experts thoughts on this?

Hi awesome community of Treehouse developers!

Got a burning question in me that directly effects my work.

Currently creating a website that makes use of a weather API that can accept up to 1000 requests a day before charging you. We don't need the weather data everytime someone visits the site, just everytime a user wants to put a post which could be once a month, however at the moment it is requesting per page view. Rather than relying on the API we think It would be better to take the API data for the date the post was posted and store it alongside the WordPress DB. We were thinking of keeping the data in a custom post type to keep in line with the WordPress DB but wondered if there was a better way to do it?

I don't really know my way around the WordPress DB or any good documentation for it so any pointers or advice would be a huge help!

1 Answer

Austin Whipple
Austin Whipple
29,725 Points

You probably don't want to store each request as a separate custom post. From the sounds of it, you'd fill your database with 1,000 useless posts each day?

Is there any way you can initiate the API request at will? For instance, add a WordPress action on post publication that requests weather data via API and populates a custom field on whatever post type you're using. That will save the data into the database and make it usable on the front-end without clogging up your database.

Adam Duffield
Adam Duffield
30,494 Points

Had just started looking into Actions/filters as this popped up! Never knew WordPress was so awesome! Cheers for the support and direction Austin!

Austin Whipple
Austin Whipple
29,725 Points

Any time! And check out this Treehouse course on WordPress Hooks (both actions and filters) while you're at it.

Adam Duffield
Adam Duffield
30,494 Points

Beat you too it buddy ;)