Skip to content

Instantly share code, notes, and snippets.

@g-maclean
g-maclean / snippet.js
Created July 28, 2025 11:49
PropertyHive - set rent frequency units on frontend
jQuery(document).on('ph:toggleSearchDepartment', function() {
var selectedDepartment = jQuery('input[name="department"]:checked').val();
if (selectedDepartment === 'student') {
jQuery('#minimum_rent option, #maximum_rent option').each(function() {
var text = jQuery(this).text();
jQuery(this).text(text.replace(' PCM', ' PW'));
});
} else if (selectedDepartment === 'residential-lettings') {
jQuery('#minimum_rent option, #maximum_rent option').each(function() {
@g-maclean
g-maclean / snippet.php
Last active July 28, 2025 05:46
PropertyHive - PropertyFile viewing shortcode
function custom_pf_button( $atts ) {
$property = new PH_Property( get_the_ID() );
// Output the button HTML
return sprintf(
'<button class="pf-request-viewing-button" data-property-id="%s">Request Viewing</button>',
esc_attr( $property->imported_id )
);
}
add_shortcode( 'pf_viewing_button', 'custom_pf_button' );
@g-maclean
g-maclean / snippet.php
Created June 9, 2025 08:19
PropertyHive - 10ninety - Assign office based on ref prefix.
//filter for 10ninety feed that assigns an office based on if it has a prefix for that branch
add_action( "propertyhive_property_imported_10ninety_xml", "assign_office_on_10ninety_prefix", 10, 2 );
function assign_office_on_10ninety_prefix($post_id, $property)
{
// branch ID => Office ID
// find office IDs in the "Edit Office" button URL in Property Hive -> Settings -> Offices
$mappings = array(
'AB123_' => 1,
'CDE45_' => 2,
);
@g-maclean
g-maclean / snippet.php
Created June 5, 2025 15:56
PropertyHive - Acquaint XML - Import Floor area
add_action( "propertyhive_property_imported_acquaint_xml", 'import_floorarea_acquaint', 10, 2 );
function import_floorarea_acquaint( $post_id, $property )
{
if ( isset($property->floorarea) && !empty($property->floorarea) )
{
update_post_meta( $post_id, '_floor_area', (string)$property->floorarea . ' sq ft' );
}
}
@g-maclean
g-maclean / snippet.php
Created May 26, 2025 07:03
PropertyHive - Kato - Filter properties based on tag
add_filter( 'propertyhive_kato_xml_properties_due_import', 'filter_kato_properties_by_tag', 10, 1 );
function filter_kato_properties_by_tag( $properties ) {
$allowed_tags = array( 'British Museum' ); // Define your allowed tags here
$filtered_properties = array();
foreach ( $properties as $property ) {
if ($property['tags'] == null || !is_array($property['tags'])) {
continue;
}
@g-maclean
g-maclean / snippet.php
Created May 20, 2025 13:24
PropertyHive - Alto - Assign office based on custom location field
add_action( "propertyhive_property_imported_vebra_api_xml", "assign_office_on_custom_location", 10, 2 );
function assign_office_on_custom_location($post_id, $property)
{
// custom_location value => Office ID
// find office IDs in the "Edit Office" button URL in Property Hive -> Settings -> Offices
$mappings = array(
'Cambridge' => 1,
'Huntingdon' => 2,
);
@g-maclean
g-maclean / snippet.php
Last active May 15, 2025 11:19
PropertyHive - Move a location and it's children to the top of the location dropdown
// Reorder Location dropdown
add_filter( 'get_terms', 'custom_order_propertyhive_locations', 10, 4 );
function custom_order_propertyhive_locations( $terms, $taxonomies, $args, $term_query ) {
if ( in_array( 'location', $taxonomies ) && is_admin() === false ) {
$custom_order = array( 'Edinburgh', 'East Lothian' );
usort( $terms, function ( $a, $b ) use ( $custom_order ) {
$pos_a = array_search( $a->name, $custom_order );
@g-maclean
g-maclean / snippet.php
Created May 2, 2025 11:25
PropertyHive - Elementor featured properties department specific query IDs
add_action('init', 'ph_custom_elementor_query_ids');
function ph_custom_elementor_query_ids() {
add_action( 'elementor/query/featuredpropertyquerysales', 'elementor_query_featured_only_sales' );
add_action( 'elementor/query/featuredpropertyquerylettings', 'elementor_query_featured_only_lettings' );
}
function elementor_query_featured_only_sales( $query )
{
$original_orderby = $query->get( 'orderby' );
$original_order = $query->get( 'order' );
@g-maclean
g-maclean / snippet.php
Created May 1, 2025 12:54
PropertyHive - Arthur - Use ref as title
add_action( "propertyhive_property_unit_imported_arthur_json", 'use_ref_as_post_title', 10, 2 );
add_action( "propertyhive_property_imported_arthur_json", 'use_ref_as_post_title', 10, 2 );
function use_ref_as_post_title($post_id, $property)
{
if ( isset($property['ref']) && $property['ref'] != '' )
{
$new_title = sanitize_title( wp_strip_all_tags($property['ref']) );
$my_post = array(
'ID' => $post_id,
'post_title' => $new_title,
@g-maclean
g-maclean / snippet.php
Created April 24, 2025 20:23
PropertyHive - IAmProperty RTDF rewrite rules
//flush rewrite rules after adding: Dashboard->Settings->Permalinks->Save
add_action( 'init', 'iamproperty_rtdf_endpoints_rewrite_rules');
function iamproperty_rtdf_endpoints_rewrite_rules() {
add_rewrite_rule(
'^([0-9]+)/sendpropertydetails[/]?',
'index.php?rtdf=1&rtdf_action=sendpropertydetails&import_id=$matches[1]',
'top'
);
add_rewrite_rule(
'^([0-9]+)/removeproperty[/]?',