WordPress Verbra Import

WordPress Verbra Import

My client was using Verbra to manage their properties and wanted to improve on their current site, which used Verbra’s own website to host the properties details. This was not ideal and presented the following issues:

  • Control of design: Whilst Verbra will try to replicate the website design, there are elements that will not completely match. Therefore you will end up with a site that may look slightly different then you originally intended.
  • Change of URL: Users are redirected to verbra.com and this can create trust issues amongst users. It’s never ideal to redirect to another domain.
  • SEO:  With all the data being hosted on Verbra’s own website, there will be no SEO benefit to the client’s own site.

My solution was to build a WordPress website that integrated with Verbra’s Client Feed Export API and imported all properties into WordPress on regular timed intervals throughout the day.

The script would do the following:

  • Import any new properties;
  • Update information on any current properties;
  • Remove any properties that no longer exist;
  • Remove media from any deleted properties in order to keep the size of the WordPress media library at a manageable size.

Here is a snippet of the script I created.

    // Store any post ids
  $added_properties[] = $id;

  // Add property meta data
  add_post_meta($id, "property_id", $property_id , true);
  add_post_meta($id, "property_price", $priceVal , true);
  add_post_meta($id, "bedrooms", $bedrooms , true);
  add_post_meta($id, "livingrooms", $receptions , true);
  add_post_meta($id, "bathrooms", $bathrooms , true);
  add_post_meta($id, "gardens", $gardens , true);
  add_post_meta($id, "garages", $garages , true);
  update_post_meta($id, "type", $type , true);

  // Set taxonmony term
  wp_set_object_terms( $id, 7, "property_type");

  // Store all media data in array
  $images     = array();
  $epc        = array();

  foreach ($prop_xml->files->file as $file ) {
      // Get file type id
      $type = $file->attributes()->type;
      $file_id = $file->attributes()->id;

      // Get file url
      $url      = $file->url;
      $post_id  = $id;

      $tmp = download_url( $url );
      $desc = $title;
      $file_array = array();

      // Set variables for storage
      // fix file filename for query strings
      preg_match('/[^\?]+\.(jpg|jpe|jpeg|gif|png|pdf)/i', $url, $matches);
      $file_array['name'] = basename($matches[0]);
      $file_array['tmp_name'] = $tmp;

      // If error storing temporarily, unlink
      if ( is_wp_error( $tmp ) ) {
        echo 'tmp file error<br>';
        @unlink($file_array['tmp_name']);
        $file_array['tmp_name'] = '';
      }

      // do the validation and storage stuff
      $img_id = media_handle_sideload( $file_array, $post_id, $desc );

      // If error storing permanently, unlink
      if ( is_wp_error($img_id) ) {
        echo ' file error<br>';
        @unlink($file_array['tmp_name']);
        return $img_id;
      }

      $src = wp_get_attachment_url( $img_id );

      if($file_id == 0){
        $image_path_large_id = $img_id;
      }

      switch ($type) {
          case '0':
                echo 'its an image\n';
                $images[] =  $img_id;
              break;
          case '9':
            $epc[] = $img_id;
          default:
              break;
      }
  }

  // Save meta image data
  if(!empty($images))
      update_post_meta($id,'property_secondry_images_id', $images );
      unset($images);

  if(!empty($epc))
      update_post_meta($id,'epc_media', $epc);
      unset($epc);

  if(!empty($image_path_large_id ))
      update_post_meta($id,'property_main_image_id', $image_path_large_id );
      unset($image_path_large_id ); 

 

If you are interested in integrating Verbra into WordPress, please get in touch.