• Hi,

    As part of the redesign of a car garage website in WordPress, my client would like to display a list of vehicles contained in a csv file he receives each week. So every week, I must update the list presented on the site by adding new vehicles and removing sold vehicles.

    I have good PHP / MySQL knowledge but I ‘ve never done custom code like this in WordPress. I wanted a few tracks or confirmation regarding the implementation of a solution.

    That’s what I think to make:

    – a PHP function to parse the CSV file in order to extract each entry (vehicle)

    – a function (a plugin for example) which call the parser function. For each entry, it checks if it exists in the WordPress DB. If not, I insert the entry with a insert_custom_post. I keep all the id in order at the end to be able to do the reverse to remove the sold vehicles.

    Where I don’t exactly know what to do, is what type of post to use. I want to be able to perform research on these posts (vehicles type) kie brand, year, kilometers or price.

    I think I have to create a custom post type (maybe two ? one for the global list, one for the detailed vehicle ?).

    Is anybody can tell me more about this king of development ?

    Thanks a lot
    Nice day,

    Bastien

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    In general, it sounds like you’re on the right path. You definitely want a custom post type for listings. it’s not too difficult to query listings based on data stored in postmeta, that is where I would store the data.

    It could be more efficient to store such data in a custom table, but I’m guessing the inventory size you’re anticipating isn’t really huge, so postmeta should be fine. You still need to decide if you should store everything in a structured array or under individual keys. The array is more efficient but more difficult to query.

    Another option for some content is of course your suggested second post_type, but I am not that enamored with that idea. Having everything keyed to a single ID is fairly important.

    Curiously, how to store the various bits of data is similar to the issues encountered with multilingual sites. Reviewing the various options there along with the pros and cons should be helpful to you for deciding on the best approach.

    Thread Starter bastien31

    (@bastien31)

    Thanks bcworkz for the quick reply.

    I’m happy to see that I am in the right direction. As you mention, the inventory size will not be huge. I’m going to tried with postmeta on a small sample (fake data with just two parameters) to try the validity of this solution.

    I noted your remark for my second post_type and I think you are right. I can of course bound the two post_type by their id in for example a hidden field, but I think it’s to complicate things for nothing.

    Have a great day!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘CSV import and post automatic creation’ is closed to new replies.