Learning PHRets and DMQL for MLS Listings Display

PHRets and MLS Listings Integration

by Adam Watts

I've always been the kind of person that isn't intimidated by a large project or a problem - which is why I jumped at the opportunity to work on a website that involved updating and displaying MLS® listings from our local MLS® provider here in Calgary, AB. In one word, this phrets project was: humbling. I've been a website designer and developer since 2006 and working with WordPress since 2010, and felt confident in working in several languages. Then - in steps the world of the MLS®. If you're unfamiliar with the coding convention of the MLS® as I was, here's a small breakdown of the processes and standards: there pretty much are none. Each region controls data with a system built custom, offering no solid connection between naming convention, data offered or access. Of course, this made it extremely difficult to follow any tutorials on the subject, though I did find a few immensely valuable sites that either guided and helped me along the way. I've listed a few of the key websites that may help you figure out what approach you need/want to use to retrieve that data and post it to your site.

Websites to Reference

These websites may not all apply to your situation, but they applied to mine.
  • - RETSMD Website : login with your credentials to view data from your MLS® feed
  • - PHRets Github Page : PHRets is an open-source, pre-built script for connecting to a RETS feed
  • - WordPress CODEX : I created a custom plugin to update and display the data
I must have spent hundreds of hours sifting through bad information, broken code and dead ends to find a few options that worked for me. Now that I have you feeling sorry for me - or more likely for yourself - for deciding to build a RETS feed display, we can get in to how it actually works and why it took me so long to get through. Hopefully I can save some folks a little time and frustration. PHREts MLS Listings screenshot - full property viewI know have a fully functioning, updating RETS feed, installed on my client's website. The data is pulled and stored into a database and displayed on the website in various places. Images are pulled from the MLS® server and displayed on page load, to decrease the amount of disc space needed to store the images locally.

1. Use PHRets

I did a lot of searching online for solutions to the problem. Most of the monthly services didn't include Calgary - which is the region I needed - and didn't offer any serious customizing options, which was a requirement of the client. I stumbled on a few pre-built code options, including a few free WordPress plugins and themes that claimed to be able to connect to a feed - but again, didn't work in my region because none of the variables are set to the same names. Plus I didn't want to pour through someone else's code in hopes that it actually did work. PHRets ended up being the best option in my case because it runs on PHP and is open-source, therefore has lots of documentation and a decent amount of forum threads on usage. In my case, I was unable to use the 2.x branch of the code because of the age of the RETS feed I was pulling from (hopefully yours is using newer code). If you do have the ability, run the 2.x branch and install it with Composer.

2. Visit RETSmd.com and Stay There!

I had a window with retsmd.com open almost the entire time I was working on the listings display. This is essential to know the values you're working with, objects and specific options available to you. To use RETSmd, you'll need login credentials for an MLS® region. This means buying in to access their data yourself, or, more likely, working on this for a client who has purchased their licence. You'll need the RETS feed URL, USERNAME and PASSWORD to connect and see what data you're allowed to access I found most of the data and values that I needed from an object called 'Listings' - though it's likely to be named differently by your feed provider.

3. Use DMQL Once You've Connected

DMQL is the language that you'll be using once you've established a connection. A quick search on Google will show you many websites with information and tutorials on DMQL, and if you're good with PHP, you should be fine with wrapping your brain around it. DMQL is an extremely touchy language. If you don't have your syntax, options and variable names all correct, nothing will happen. I spent many hours trying to figure out why a connection wasn't retrieving any results, and it was usually to do with a slight error in syntax.

4. Turn Error Reporting On and Check It!

Debugging code and deciphering errors was the main challenge here. Make sure that you have turned error reporting on, however you do it (depending on the system or language you're using) and print results to your page while you're working on retrieving results and connecting.  

Read More Soon!

To keep things readable, I'm not going to go in to detail on these topics here - that's for another post, another day - and will be on the subject of creating an initial PHRets connection - with PHRets 1.x. Stay tuned for more information on this subject and more general website development, design and optimizing ideas, thoughts and musings. If you have any questions, feel free to leave a comment below.