Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save propertyhive/97294618e14e9d82d6af9fc92ea7d6d2 to your computer and use it in GitHub Desktop.
Save propertyhive/97294618e14e9d82d6af9fc92ea7d6d2 to your computer and use it in GitHub Desktop.
add_action( "houzez_property_feed_property_imported_xml", 'import_custom_features', 10, 4 );
function import_custom_features( $post_id, $property, $import_id, $instance_id )
{
wp_suspend_cache_invalidation( true );
wp_defer_term_counting( true );
wp_defer_comment_counting( true );
wp_delete_object_term_relationships( $post_id, "property_feature" );
// Heating
if ( isset($property->heating) )
{
foreach ($property->heating as $heating )
{
if ( isset($heating->heating_type) )
{
$heating_types = array();
foreach ( $heating->heating_type as $heating_type )
{
$heating_types[] = (string)$heating_type;
}
if ( !empty($heating_types) )
{
$feature = 'Heating: ' . implode(", ", $heating_types);
wp_set_object_terms( $post_id, $feature, "property_feature", true );
}
}
}
}
// furniture
if ( isset($property->furniture) )
{
foreach ($property->furniture as $furniture )
{
if ( isset($furniture->furniture_element) )
{
foreach ( $furniture->furniture_element as $furniture_element )
{
wp_set_object_terms( $post_id, (string)$furniture_element, "property_feature", true );
}
}
}
}
// Equipment
if ( isset($property->equipment) )
{
foreach ($property->equipment as $equipment )
{
if ( isset($equipment->equipment_element) )
{
foreach ( $equipment->equipment_element as $equipment_element )
{
wp_set_object_terms( $post_id, (string)$equipment_element, "property_feature", true );
}
}
}
}
// Other
if ( isset($property->other) )
{
foreach ($property->other as $other )
{
if ( isset($other->other_element) )
{
foreach ( $other->other_element as $other_element )
{
wp_set_object_terms( $post_id, (string)$other_element, "property_feature", true );
}
}
}
}
wp_suspend_cache_invalidation( false );
wp_defer_term_counting( false );
wp_defer_comment_counting( false );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment