0

I have a URL provided by my Real Estate service that lists, in a XML file, every apartment and house that I have to sell.

The XML url lists every detail of every apartment, things like images, year of building, floor, prices, rent, etc.

I need to create a Real Estate WordPress website where I can list, from this url, all those apartments and house and also show a filter where I can filter apartaments by price, by location, etc.

Maybe I could implement a Custom Post Type named "Properties" and set their details in custom metaboxes.

My main doubt is how to parse this XML periodically and update info in those metaboxes/post types in WordPress.

Thanks!

0

I would definitely recommend the Custom Post Type route. You will have two issues:

  1. How to automatically add new properties when the XML is updated.
  2. How to update existing property values if they change (e.g., House A has a price increase after the initial import).

To solve the first, you can set up a WordPress cron that will hook into your import action. Read more on the WP Cron - it does not run like a traditional server-based cron so it may not match your needs.

For the second issue of updating data, there are several ways to do this. One way would be to save a hashed version of the data that is being imported. For example, if your XML looks like this for House A:

<property>
    <title>House A</title>
    <price>$100</price>
    <bedrooms>3</bedrooms>
    <bathrooms>2.5</bathrooms>
</property>

You can take that whole string and pass it through a hash function like wp_hash which would give you something like this: f0605d40e0d52c56803be67d4f08742a (not exactly this, this is just MD5).

Then, if your data changes (price goes up to $200, for example), during the import process you can hash again and double-check if the hash matches the existing property. If I use the same process to hash the data at $200, we get this: 67929e91190420a69ac258f78b6f1777. If your script detects a difference, then re-import that property.

You will need to be able to match properties another way, however. My recommendation would be to create a slug out of the property title or match it via some sort of ID based on the XML side. If each property has an ID from the XML, save it as custom meta in the property post and match those.

One last thing to look into: If you would rather not deal with code, you may be able to use a tool like WPAllImport, which allows you to set up custom feeds for XML and other sources.

Hope all this helps!

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.