Skip to content

Instantly share code, notes, and snippets.

@imperialjeff
Created November 11, 2024 22:05
Show Gist options
  • Save imperialjeff/bc4277c36eb2c276035509f5dcc5d36d to your computer and use it in GitHub Desktop.
Save imperialjeff/bc4277c36eb2c276035509f5dcc5d36d to your computer and use it in GitHub Desktop.
add_action("propertyhive_property_imported_dezrez_json", 'set_new_home_flag', 10, 2);
function set_new_home_flag($post_id, $property) {
wp_suspend_cache_invalidation(false);
wp_defer_term_counting(false);
wp_defer_comment_counting(false);
$flags = array();
if (isset($property['Descriptions']) && is_array($property['Descriptions']) && !empty($property['Descriptions'])) {
foreach ($property['Descriptions'] as $description) {
if (isset($description['StyleType']['SystemName']) && trim(strtolower($description['StyleType']['SystemName'])) == 'new') {
$flags[] = 69;
}
}
}
if (isset($property['Price']['PriceQualifierType']['SystemName']) && $property['Price']['PriceQualifierType']['SystemName'] == 'SharedOwnership') {
$flags[] = 74;
}
if (isset($property['Tags']) && !empty($property['Tags'])) {
foreach ($property['Tags'] as $tag) {
if (isset($tag['Name']) && $tag['Name'] == 'shared_ownership') {
$flags[] = 74;
}
}
}
// availability flags
if (isset($property['Flags']) && is_array($property['Flags']) && !empty($property['Flags'])) {
foreach ($property['Flags'] as $flag) {
if (isset($flag['SystemName']) && !empty($flag['SystemName'])) {
if ($flag['SystemName'] == 'OfferAccepted') {
$flags[] = 75;
}
}
}
}
if (!empty($flags)) {
wp_set_post_terms($post_id, $flags, 'marketing_flag');
}
wp_suspend_cache_invalidation(true);
wp_defer_term_counting(true);
wp_defer_comment_counting(true);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment