Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save propertyhive/45ca0ed020dd892c4e0498130b0a48b0 to your computer and use it in GitHub Desktop.
Save propertyhive/45ca0ed020dd892c4e0498130b0a48b0 to your computer and use it in GitHub Desktop.
add_action( "propertyhive_property_imported_reapit_foundations_json", 'trim_postcode', 10, 2 );
function trim_postcode( $post_id, $property )
{
$explode_postcode = explode(" ", $property['address']['postcode']);
$address_fields_array = array_filter(array(
$property['address']['line1'],
$property['address']['line2'],
$property['address']['line3'],
$property['address']['line4'],
$explode_postcode[0],
));
$post_title = implode(', ', $address_fields_array);
$my_post = array(
'ID' => $post_id,
'post_title' => wp_strip_all_tags( $post_title ),
'post_excerpt' => ( ( isset($property['description']) ) ? $property['description'] : '' ),
'post_status' => 'publish',
);
// Update the post into the database
$post_id = wp_update_post( $my_post, true );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment