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.

  • @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? Commented Nov 9, 2010 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
    Commented Nov 9, 2010 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. Commented Nov 10, 2010 at 2:38

1 Answer 1


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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