1

I am writing a plugin that needs to store data for a day (everyday). The data is retrieved from a CSV file.

I will be retrieving three columns of financial data (Fund ID, Fund Description and Price) from the CSV files. The Fund ID and Description will be text and the price will obviously be in a currency. The number of entries in each CSV file will be less than 100.

The data will then be used in various posts (by referencing a short code) but I have a question about how to store this data so that it is accessible from multiple posts. When I say used, the fund price will be displayed - that is all.

I can store data using the add_post_meta functionality within my WordPress plugin. But logically speaking that is storing the data in the context of a particular post. I imagine that I could just "choose" a post ID and always store (and retrieve) the data from there. I can think of all sorts of these weird schemes to get this right but I was wondering if there is an accepted way to do this without creating a custom table in the database. I am just looking to be nudged in the correct direction, any thoughts would be appreciated.

UPDATE: Thanks to @Jacob Peattie for the suggestion of refining the question.

  • It really depends on what the data is, how much there is, and what you need to do with it. You're vague on all 3. Unless you can provide more specifics this will probably be closed as "too broad". – Jacob Peattie Oct 21 '17 at 15:56
  • Thanks, @jacob-peattie - I have added some detail which I hope clarifies my question. – Haemish Kyd Oct 21 '17 at 16:26
  • Fund ID = post_title, Fund Description = post_content, Price = via add_post_meta, you can write a shortcode that access these as needed. – majick Oct 21 '17 at 16:26
  • sorry getting ahead of myself you should start with lookig at register_post-typefor registering a post type of fund – majick Oct 21 '17 at 16:32
  • Thanks, everyone. I think I got a good idea how to proceed. – Haemish Kyd Oct 22 '17 at 9:41
1

Using a taxonomy is probably the best way. Creating a CPT will be the second option. The problem with CPTs is that you will need to store data in the mesta table which will most likely have some performance impact on other things being done on the site. Taxonomy term meta data is less bloated and you will have the advantage of being able to associate the posts with the terms representing the funds being refereed in it.

The disadvantage of using taxonomy is that the UI for editing term data sucks more than the post meta data UI. (yes, you most likely will need UI if only for testing that your csv "import" works well, and it is useful to be able to make small changes without regenerating the whole CSV).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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