Integrate Shelter Buddy with WordPress & Increase Pet Adoptions

We’ve seen it time and time again. Non profits and charitable organizations with websites that need a facelift. None are more familiar with this than animal shelters. The logic does make sense, as inconvenient as it is for the end-user. Saving animals takes precedence over a highly use-able website, as funds can only go so far. That’s when cheap lodoking adoptions pages creep into existence. Text only adoption pages, or the dreaded iframe embeds to a 3rd party system, meaning off-site content that you can’t do a thing with. But what if there was a way to easily improve the way animal shelters showcase their pets for adoption using Shelter Buddy – a popular animal shelter management application.

We recently donated a website to Regina Humane Society, my local Animal Shelter here in Regina, SK. They take in pets of all age, breed, temperament, or health and have a strong standing in the Regina community. We wanted to give this idea a whirl, and it proved to be highly successful. In an effort to share what we’ve learned and hopefully help other animal shelter’s out, here’s how we integrated shelter buddy with wordpress.

Obtain XML/ASPX from Shelter Buddy

Shelter Buddy accounts are provided with a unique URL for embedding adoptable pets via iframe. While this was useful once upon a time, in the modern day of API’s, Plugins, and ensuring content is on-site, this just won’t do. Talk to Shelter Buddy support and get access to your Shelter Buddy XML/ASPX file. It’ll look something like:

http://yoursheltername.shelterbuddy.com/DataFeeds/AnimalsForAdoption.aspx

Setup Your WordPress Environment

What we want is for each pet to have its own unique post in WordPress. We’ll need to pull in each pet listed for adoption and grab the data from Shelter Buddy and set it to custom fields or taxonomies. This all has the added benefit of providing additional content for your website, a big plus if you’re concerned with search engine optimization. Before we can start pulling in data from that Shelter Buddy data feed we’re going to need to setup our wordpress environment to handle more than just Pages & Posts.

custom post types animal shelter buddy

Things we’ll be adding to the environment:

  1. A Custom Post Type for Pets
  2. A Custom Taxonomy for Pet Types (ie: Dogs, Puppies, Cats, Kittens, Rabbits, Birds, etc)
  3. Custom fields for:
    1. Pet Breed (ie: Border Collie or Terrier for dogs, Turtoiseshell or Siamese for Cats, etc)
      [Note: this could go in a taxonomy instead, we chose not to go that route]
    2. Shelter Buddy ID
    3. Gender
    4. Pet Colour
    5. Is the Pet Spayed/Neutered
    6. Pet Age
    7. Pet Weight
    8. Any other fields from the Shelter Buddy Data Feed that you might want to include.

Setup a Custom Post Type for Pets and Custom Taxonomy for Pet Types

Let’s keep WordPress clean and tidy by separating the Pet data from the posts or pages. Justin Tadlock has a great tutorial on adding custom post types. Typically we include them via mu-plugins, that way if they ever change themes, the data is still retrievable.

We’ve also included the Pet Types taxonomy – which is being attributed to the ‘base_pets’ post type. Once this is all created we’ll be a couple steps closer to having a fine tuned system in place.

Setup Custom Metabox with Custom Fields for Shelter Buddy Data

You’ll need to be fluent in adding custom fields for this to make much sense. Consider check out Jared Atchison and Bill Ericksons Custom Metaboxes and Fields for WordPress on Github. It’s very nicely documented and explains the process and provides several examples.

Test Your New Environment and Add Hierarchical Template Structures

Give your new additions a whirl. Throw some dummy content in there to make sure things are working as intended. Then make sure that you’ve got all of the php files you need to make your new content shine. Such as:

  1. single-base_pets.php – The singular page for each pet – you may want to style it a bit differently than your blog posts. Try duplicating your single.php and going from there.
  2. content-base_pets.php – Your theme should load a separate template for the content inside of the single.php is to accommodate for multiple post types. It makes life much easier, trust me. See Codex on Template Hierarchy.
  3. adoptions.php – The overview of all pets for adoption, we recommend setting this up as a page template. Use a query t
  4. taxonomy-base_pet_types.php (optional) – If you’ve enabled the ability to browse by taxonomy you might want to setup these pages to look different than your category or archive pages.

Show Your New Pet Data Custom Fields

Here’s an example of showing what your content-base_pets.php would look like. We’re just defining some variables, then showing them with a conditional if variable is not empty echo data out. You would use similar techniques within a custom query for an overview page template. You can do some incredible things with this type of data, such as integrating it with filters, such as those seen on MixItUp – which is what we did for the Regina Humane Society adoptions page.

Import Content from Shelter Buddy Data Feed

Okay – so your fields and custom post types are setup.Your data is showing on the front end, you might have even spent some time really fleshing it out to look pretty. Nice work! Go remove all of the dummy data you created before testing out this next bit.

All that’s left is to start getting that data from Shelter Buddy’s data feed. While there’s countless ways you could pull that data in via PHP, the easiest and most foolproof method we came across is with the help of WP All Import by Soflyy. If you’ve ever needed to import some funky XML or CSV files and find a way to place data into the appropriate fields, WP All Import is a huge time-saver.

shelter buddy wordpress integration

Using their drag and drop interface you can select specific elements and attributes and set them to specific fields, such as the ‘base_pets’ title, the content, or any of the custom fields or taxonomy terms we’ve set. You can even pull in the image URL and instruct WP All import to store the image on your server and set it as the featured image.

Once your fields and title and content are set to grab the appropriate data, just run the import! Depending on your hosting account, this could take a while. But you’ll soon find that your backend is filled with pets, waiting for adoption.

Note: One thing we should warn you about. Ensure that your hosting account doesn’t have a low phptimeout as this process takes a while for each import. We ran into problems with WP Engine as they really lock their server settings down to keep things zippy for their customers. Consider checking out Siteground or MediaTemple if you’re going to be doing lots of large imports with multiple images. 

Now let’s automate the Pet Data import!

Wouldn’t it be great if you could pull in that data to ensure your animal shelter’s website has the most up to date pets available for adoption. Nothing angers people more than going into a shelter, with their heart set on Skippy the Three-legged Terrier, only to find out he’s been taken home by someone else.

Setup 2 Cron Jobs:

Set to run every 2 minutes (or 15 if that’s all you’re limited to, but note that the import may take longer to process)

wget -q -O /dev/null "http://YOURWEBSITE.COM/wp-cron.php?import_key=YOURKEY&import_id=YOURIMPORTIDNUMBER&action=processing"

Set to run every 15 minutes to trigger the import and instruct processing URL to instruct WP All Import to pull data from Shelter Buddy’s ASPX file.

wget -q -O /dev/null "http://YOURWEBSITE.COM/wp-cron.php?import_key=YOURKEY&import_id=YOURIMPORTIDNUMBER&action=trigger"

cron-job-shelter-buddy-import

WP All Import provides easy instructions on how to setup a cron jobs to pull that data at regular intervals. Assuming your hosting account allows cron jobs, it’s just a matter of setting up the trigger & processing URL to run every 15-20 minutes to keep the data up to date with Shelter Buddy. This can usually be accessed via Cpanel, or contact your hosts tech support and give them the URLs you need to run and let them know how often to run them. I’ve tested the Cron Job method using Easy Cron tied into WP Engine, as well as Hostgator. Though WP All Import recommends Siteground or MediaTemple due to their longer phptimeout limit. It should work for just about any host that allows for cron jobs though.

In order for your import to compare your Shelter Buddy database of pets to your WordPress Database of Pets, you’ll need to use record matching. Fortunately WP All Import comes with a couple types. Depending on your scenario, you can choose either, but I’d recommend Option 1.

Option 1: Automatic Record Matching

When you first create your import, you have the ability to set a record matching field. You can select anything from Animal ID, Post ID, etc. Whatever you do, don’t just use the animal’s name or the post title. There will likely be countless Fluffy the cats going through a shelter and you don’t want to make it easy for the system to get confused. Try using a combination of Post Title and Animal ID – which is what I’d recommend. That way when the record matching is taking place it will be able to tell that fluffy-8675309 is different from fluffy-902189. We want to avoid accidental deletion or overwrites.  The only way to change this down the road is to recreate the import template from scratch and set it properly during the import setup. So be careful when you’re creating your first import.

One drawback with this method is that the automatic record matching doesn’t allow you delete pets that weren’t placed there from a previous import. So if you’ve done any database migrating, you might find a few pets that have already been adopted won’t get removed automatically. If you’re going to use Automatic (which I recommend) just be sure to delete all pets and clear the trash and start from a fresh import, especially if/when you’re migrating from local to staging to live servers.

Option 2: Manual Record Matching

If you don’t ever plan on deleting animals, or plan on manually deleting pets when they’ve been adopted (kind of defeats the purpose, but hey whatever floats your boat) then this route will suit you just fine.

If you have to go this route, I’d recommend setting up Manual Record Matching via the Shelter Buddy animal id. By setting manual record matching the import script can compare all posts within your custom post type, rather than the posts from the last imports. Just note that this method does not allow you to delete posts automatically.

Boom Shakalakalaka

Just like that you’ve integrated Shelter Buddy with WordPress. No ghetto iframes, just pure styled inline content that you have complete control over. Throw some jquery or php queries to allow users to filter pets by their preferences and you’re set. I’ve spoken with Shelter Buddy’s lead developer and he informed me that they’re working on an API but that it’s a ways away. So for now, this is the best way to get these two systems to work together.
View Demo
If you have any questions please contact us or leave us a comment below. If you’re a Humane Society or an Animal Shelter in need of a custom website design or just need a point in the right direction, please don’t hesitate to reach out.

Update: Fixed Cron Job Trigger and Execution Script.

Update 2: Some people are reporting Pets being placed into schedule format instead of published format after import. See this WP Beginner Tutorial on Fixing Missed Schedules or if you aren’t using the publication date for anything you could set the post date to any date before the current date.

Update 3: After WP All Import 4 came out my imports stopped working. I just ended up recreating them from scratch and updated Import Speed Optimization settings to Iterative, piece by piece processing (20 records per iteration) and disabled split file into 1000 record chunks. This allowed it to proceed with the imports. 

Share on:

Leave a Reply

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">