Skip to content

Instantly share code, notes, and snippets.

@g-maclean
g-maclean / snippet.php
Created February 21, 2026 11:53
Property Hive - Remove floorplan from actions
add_filter( 'propertyhive_single_property_actions', 'remove_floorplans_action' );
function remove_floorplans_action( $actions )
{
foreach ( $actions as $i => $action )
{
if ( isset( $action['class'] ) && $action['class'] === 'action-floorplans' )
{
unset( $actions[ $i ] );
}
}
@g-maclean
g-maclean / snippet.php
Created February 20, 2026 16:53
Property Hive - Property count shortcode
// Shortcode: [ph_active_properties_count department="residential-sales"]
add_shortcode( 'ph_active_properties_count', function ( $atts ) {
$atts = shortcode_atts([
'department' => '',
], $atts);
$meta_query = [
[
'key' => '_on_market',
@g-maclean
g-maclean / snippet.php
Created February 20, 2026 06:31
Property Hive - Street - Leasehold Years Reamining rounded up
add_action( "propertyhive_property_imported_street_json", function( $post_id, $property ) {
if ( isset( $property['attributes']['tenure'] ) && $property['attributes']['tenure'] == 'Leasehold' && isset( $property['attributes']['lease_expiry_date'] ) && is_numeric( $property['attributes']['lease_expiry_date'] ) ) {
$date1 = new DateTime();
$date2 = new DateTime( $property['attributes']['lease_expiry_date'] );
$days = $date1->diff($date2)->days;
$years = ceil($days / 365.2425); // round up
@g-maclean
g-maclean / snippet.php
Created February 19, 2026 11:17
Property Hive - XML feed - Automatically tick Rightmove
add_action( "propertyhive_property_imported_xml", function( $post_id, $property, $import_id ) {
update_post_meta( $post_id, '_realtime_portal_0', 'yes' );
}, 10, 3 );
@g-maclean
g-maclean / snippet.php
Created February 18, 2026 16:13
Property Hive - Properties Shortcode - Maintain sorting by price when meta_key is defined in atts
// currently, when meta_key is used in the properties shortcode it effectively remvoes the price sorting, this restores it
add_filter( 'propertyhive_shortcode_properties_query', function( $args, $atts ) {
// Only apply when shortcode is filtering investment properties
if (
empty( $atts['meta_key'] ) ||
$atts['meta_key'] !== '_investment_property'
) {
return $args;
}
add_action( 'propertyhive_property_imported_street_json', function( $post_id, $property ) {
wp_suspend_cache_invalidation( true );
wp_defer_term_counting( true );
wp_defer_comment_counting( true );
$is_on_market = false;
if ( isset( $property['lettingsListing'], $property['lettingsListing']['status'] ) ) {
$status = trim( (string) $property['lettingsListing']['status'] );
@g-maclean
g-maclean / snippet.php
Created February 6, 2026 12:29
Property Hive - Street - Use Line 2 if it is the number + street address
add_action( 'propertyhive_property_imported_street_json', function( $post_id, $property ) {
if ( empty( $property['address']['line_2'] ) ) {
return; // nothing to do
}
$line_2 = trim( $property['address']['line_2'] );
$parts = explode( ' ', $line_2 );
// Match: 100, 100b, 12A etc
@g-maclean
g-maclean / gist:ee66c1e6db57e9585a88fa2a7bb80f02
Last active February 11, 2026 12:57
Property Hive - WP Residence - assign user based on import ID
add_action( "propertyhive_wpresidence_property_synced", 'set_property_user', 10, 3 );
function set_property_user($property_id, $post_id, $synced)
{
// Import ID => WordPress User ID
$import_to_user_map = array(
'1000000' => 10,
'1000001' => 11,
'1000002' => 12,
);
@g-maclean
g-maclean / gist:5e3b8d9169e1af74bcdd1b0fd870c020
Created January 27, 2026 07:18
Property Hive - Search Form - Only display specific property types
add_filter( 'propertyhive_form_taxonomy_terms_args', 'custom_form_taxonomy_terms_args', 10, 2 );
function custom_form_taxonomy_terms_args( $args, $field ) {
if ( $field['type'] == 'property_type' ) {
$args['include'] = array( 1, 2, 3 ); // Replace with your desired term IDs from Property Hive -> Settings -> Custom Fields -> Residential Property Types
}
return $args;
}
@g-maclean
g-maclean / snippet.php
Created January 22, 2026 09:45
Property Hive - Reapit Foundations - Use address fields for Locations
// for use when the embedded area isn't populated or doesn't work for some reason
add_action( "propertyhive_property_imported_reapit_foundations_json", "assign_location_from_multiple_fields", 10, 2 );
function assign_location_from_multiple_fields( $post_id, $property ) {
$location_set = false;
$fields_to_check = array( 'line2', 'line3' );
foreach ( $fields_to_check as $field ) {