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

Andrew Folts
Andrew Folts
14,238 Points

How do you like to handle bulk data entry when developing Wordpress sites?

I do a lot of sites for restaurants with big menus, and I'm getting tired of inputting all this data manually!

How do other developers automate data entry (say for products, etc) to make it faster/easier?

2 Answers

Sue Dough
Sue Dough
35,800 Points

MYSQL, CSV's, WPDB , etc. Its hard to know the best solution for you with such little info. Theres a lot of things unknown. I would be interested in knowing about the data schema. If its the same every time then automation would be the way to go for sure. If your schema is not the same, try to figure out how to make it the same. Once you have steady data schema then the rest should be pretty easy. Theres no right way to do it, there is a lot of ways. FIgure out what works best for your situation.

Andrew Folts
Andrew Folts
14,238 Points

Here's a basic example. I have food menu items with the following data: Name, Prices, Sizes, Ingredients, Category, Featured Image, etc. The data schema would be the same for every item.

What I'm currently doing is manually inputing all this data into Custom Posts with ACF repeater fields (not fun). I'd like to be able to give a formatted spreadsheet to the client and then just import it, but I'm not sure where to start. Do you know of any tutorials or articles that would be good for understanding the general process or different approaches? Thanks!

Sue Dough
Sue Dough
35,800 Points

Okay well this is what I would reccomend.

First thing first you need to create a custom post type for food or whatever you want to name it.

Then you need to create custom fields. You can save yourself some time and use http://jeremyhixon.com/tool/wordpress-meta-box-generator-v2-beta/ to generate a fields class.

Each menu item would be a custom post and each data point can be 1 field.

Your not going to find an easy solution to replace repeater fields so your probably going to need to rethink this. Using repeater fields is not good anyways because it uses a lot of meta rows. So lets rethink the schema.

What you could do for things with multiple items is json_encode to turn it into json data so your only using meta value in the database for that data point. Simple example:

$ingredients = json_encode( array( 'ingredient-1', 'ingredient-2', 'ingredient-3' ) );

if ( isset( $ingredients ) ) { 
  update_post_meta( $post_id, 'food_ingredients', $ingredients )
};

Then when you want to use the data you can simply json_decode it. Simple example:

$ingredients = get_post_meta( $post_id,  'food_ingredients',  true );
$decoded      = json_decode( $ingredients );

// This will print all the data so you can see
print_r($decoded);

With this solution the biggest hiccup will be getting the data pieces that have multiple pieces and making those json ready. However it will allow a nice schema, use a small db size, is scalable, and you'll be able to ditch advanced custom fields.

CSV's and spreadsheets can be tricky sometimes however PHP does have good support functions for them. Ideally I would probably either use a form and the things that have multiple data points could be separated on new lines in a text area and then turned into an array for each line and then encoded into json. Or you could write a script to make some of the spreadsheet turn into json where needed. If you have a nice structured CSV there is plenty of plugins that will do the job importing it

These are just some ideas. I hope they get you started. Remember at the end of the day the simple solution usually wins so if you think of something simpler, then take that route.

Andrew Folts
Andrew Folts
14,238 Points

Ah that's interesting! Thanks for pointing me in the right direction. I'll try experimenting with this and see where it takes me. Cheers!

Sue Dough
Sue Dough
35,800 Points

Hi Andrew,

You could also seperate it by commas and not store array/use json to make things simpler. I was just thinking about this. You'll need to way out the pros/cons of both and do what you thinks best. If you need everything very organized and each ingredient etc very clean then I would reccomend json. However if you want to just echo out some ingredients then it doesn't matter too much. You can also use explode function to seperate things by comma and stuff in PHP.

jason chan
jason chan
31,009 Points

look for csv importer to wordpress