Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Looking for advice for the best method to accomplish the following.

I have a custom page template with several custom fields/taxonomy.

The data needed for these custom fields actually resides in .txt files that are updated once a week. They are easily converted into .csv files. What would be the best and most secure method in getting this data into a custom page template, I figure I have 3 options.

Read the raw .txt or .csv files using custom php? Import the .csv into a separate database and grab the data from it? Import the data into the WordPress database?

Option 3 seems to be the best one, but I am completely unfamiliar with the wordpress database structure and the best way to go about this.

share|improve this question
    
@user1509 - If you can give more specifics of your use-case and your data format including your field and template it will make it easier for us to help you. Also when you say "getting this data into a custom page template" do you mean "getting this data into the WordPress database so it can be displayed with a custom page template?" And you make no mention of using a Custom Post Types + related Theme Template file which it seems is what you probably want instead of a custom page template; am I wrong? –  MikeSchinkel Nov 9 '10 at 7:51
    
Well I am using a custom post type in a child theme which is no problem. The data I need is in a .txt file, something like a serial # with several meta values per number. The reason is the data is often updated like once a week or so. I figure the easiest way is to just import it directly using php but I also want to take advantage of wordpress functions, for instance making the data part of a category or tag ( any array really). –  Wyck Nov 9 '10 at 22:26
2  
I would do it with a one-off php function in your functions.php attached to a wp hook that you can trigger, let the import happen, and then disable. You definitely want to use WordPress functions to add posts and manipulate the database... no sense reinventing the wheel. If you'll need to do it regularly, write a basic plugin that takes an uploaded csv, parses it, and handles creating the posts for you. –  goldenapples Nov 10 '10 at 2:38
add comment

1 Answer

up vote 4 down vote accepted

Unlikely that you will need intermediary database, from your description this is likely to be easy enough with bit of PHP and WP APIs.

  1. Create WP-Cron task (if you need automated recurrent import).

  2. Read data from flat files, for example with fgetcsv().

  3. Use wp_insert_post() for creating posts and custom field functions to add your data. This was recently covered in detail in WP insert post PHP function and Custom Fields question.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.