Skip to content

Filters & Hooks: Examples

WP-ImmoMakler provides numerous WordPress filter hooks and action hooks that allow you to customize outputs and importer behavior from your own code. All code examples belong in the file /wp-content/plugins/immomakler-child/functions.php of your WP-ImmoMakler Child-Skin-Plugin.

Redirect to a custom confirmation page after the contact form is submitted:

add_filter('immomakler_contactform_mailsent', 'immomakler_mailsent', 10, 3);
function immomakler_mailsent($text, $requested_items, $values) {
$objektid = $requested_items[0];
return $text . '<script>location.href="/anfrage-gesendet/?id=' .
get_post_meta($objektid, 'objektnr_extern', true) . '";</script>';
}

Trigger analytics events on form submission

Section titled “Trigger analytics events on form submission”

For the standard case, WP-ImmoMakler → Settings → Contact Form provides the Analytics event on form submission option — no custom code is required for that, see Configuring the contact form. The following examples are useful if you need additional, custom event parameters.

add_filter('immomakler_contactform_mailsent',
'immomakler_contactform_mailsent_analytics_event', 10, 2);
function immomakler_contactform_mailsent_analytics_event($response, $requested_items) {
return $response . '<script>if (typeof gtag === "function") { gtag("event", "direktanfrage_versendet", { objekt_id: "' .
esc_js(get_post_meta($requested_items[0], 'objektnr_extern', true)) . '" }); }</script>';
}
add_filter('immomakler_contactform_mailsent',
'immomakler_contactform_mailsent_gtm_event', 10, 2);
function immomakler_contactform_mailsent_gtm_event($response, $requested_items) {
return $response . '<script>window.dataLayer = window.dataLayer || [];
window.dataLayer.push({ event: "form_submit_wp_immomakler",
objekt_id: "' . esc_js(get_post_meta($requested_items[0],
'objektnr_extern', true)) . '" });</script>';
}

To include custom meta fields in WP_Query search queries:

add_filter('immomakler_searchable_postmeta_keys',
'custom_immomakler_searchable_postmeta_keys');
function custom_immomakler_searchable_postmeta_keys($immomakler_metakeys) {
$immomakler_metakeys[] =
'verwaltung_objekt-user_defined_simplefield-objekt_des_tages';
return $immomakler_metakeys;
}

Configure slider-based search fields for area, number of rooms, and price:

add_filter('immomakler_search_enabled_ranges',
'my_immomakler_search_ranges');
function my_immomakler_search_ranges($ranges) {
return array(
'immomakler_search_size' => array(
'label' => 'Fläche',
'slug' => 'qm',
'unit' => 'm²',
'decimals' => 0,
'meta_key' => 'flaeche',
'slider_step' => 5,
),
'immomakler_search_rooms' => array(
'label' => 'Anzahl Zimmer',
'slug' => 'zimmer',
'unit' => '',
'decimals' => 1,
'meta_key' => 'anzahl_zimmer',
'slider_step' => 0.5,
),
'immomakler_search_price_rent' => array(
'label' => 'Kaltmiete',
'slug' => 'kaltmiete',
'unit' => '€',
'decimals' => 0,
'meta_key' => 'kaltmiete',
'slider_step' => 100,
),
'immomakler_search_price_buy' => array(
'label' => 'Kaufpreis',
'slug' => 'kaufpreis',
'unit' => '€',
'decimals' => 0,
'meta_key' => 'kaufpreis',
'slider_step' => 25000,
),
);
}
add_filter('immomakler_image_sizes', 'custom_immomakler_image_sizes');
function custom_immomakler_image_sizes($images_sizes) {
$images_sizes['immomakler-archive-thumb'] = [
'width' => 350, 'height' => 250, 'crop' => false,
];
$images_sizes['immomakler-archive-thumb-big'] = [
'width' => 475, 'height' => 300, 'crop' => true,
];
$images_sizes['immomakler-archive-big'] = [
'width' => 900, 'height' => 600, 'crop' => ['center', 'top'],
];
return $images_sizes;
}

For the height, specify at least 1.5 times the width wherever possible (without cropping). If the height is smaller than the width, the height limits the image for landscape-format photos and it is generated narrower than specified — in the display it is then upscaled and appears blurry. For more details, see Property image processing.

Update modification date on property updates

Section titled “Update modification date on property updates”

By default, the original publication date is preserved. To update the modification date on every import update:

add_filter('immomakler_preserve_post_date_on_update', '__return_false');

Create foreign country entries in taxonomies

Section titled “Create foreign country entries in taxonomies”
add_filter('immomakler_mark_foreign_countries', '__return_true');
add_filter('immomakler_object_terms_types',
'custom_immomakler_object_terms_types', 10, 2);
function custom_immomakler_object_terms_types($object_types, $openimmo_data) {
if ($openimmo_data['gewerbe']) {
$object_types[] = 'Gewerbe';
}
if ($openimmo_data['verwaltung_objekt-user_defined_simplefield-xyz'] == 'PREMIUM') {
$object_types[] = 'Premiumimmobilie';
}
return $object_types;
}
add_filter('immomakler_object_terms_nutzungsart',
'custom_immomakler_object_terms_nutzungsart', 10, 2);
function custom_immomakler_object_terms_nutzungsart($object_nutzungsart, $openimmo_data) {
if ($openimmo_data['verwaltung_objekt-user_defined_simplefield-xyz'] == 'PRIVAT') {
$object_nutzungsart[] = 'Privat';
}
if ($openimmo_data['verwaltung_objekt-user_defined_simplefield-xyz'] == 'INSTITUTIONELL') {
$object_nutzungsart[] = 'Institutionell';
}
return $object_nutzungsart;
}

Example: create a postal code taxonomy and populate it automatically during import:

add_action('init', 'custom_immomakler_register_taxonomies');
function custom_immomakler_register_taxonomies() {
register_taxonomy('immomakler_search_plz', 'immomakler_object', array(
'labels' => array(
'name' => _x('Postleitzahlen', 'taxonomy general name'),
'singular_name' => _x('Postleitzahl', 'taxonomy singular name'),
'all_items' => _x('Alle Postleitzahlen', 'taxonomy choose all'),
),
'rewrite' => array(
'slug' => 'immobilien-plz',
'hierarchical' => false,
'with_front' => false,
),
'hierarchical' => false,
'query_var' => 'plz',
'public' => true,
'show_ui' => true,
));
}
add_action('immomakler_after_post_create', 'custom_immomakler_index', 10, 2);
function custom_immomakler_index($post_id, $openimmo_data) {
if (!empty($openimmo_data['plz'])) {
wp_set_object_terms($post_id, $openimmo_data['plz'], 'immomakler_search_plz');
}
}

Check the search criteria of a property alert

Section titled “Check the search criteria of a property alert”
PLUS

With the filter immomakler_searchagents_validate_criteria you define your own rules for which search criteria a property alert may have. WP-ImmoMakler applies the filter before a property alert is created or changed and before an email is sent. If you return a WP_Error, WP-ImmoMakler rejects the property alert and shows the prospect the error’s message. If you return null, the property alert is accepted.

The filter receives three parameters:

ParameterContent
$errorThe result of the built-in check: a WP_Error if a minimum value is greater than the corresponding maximum value, otherwise null
$criteriaThe search criteria as an array, for example [ 'vermarktungsart' => 'kauf', 'von-zimmer' => '3' ]. Ranges are stored under the keys von-… and bis-…
$requestThe remaining data from the form, such as email. For a change made from the results list, the array is empty

The following example rejects property alerts with a minimum of more than 20 rooms. The built-in check is preserved, because the filter returns an existing $error unchanged:

add_filter( 'immomakler_searchagents_validate_criteria', 'meine_suchauftrag_pruefung', 10, 3 );
function meine_suchauftrag_pruefung( $error, $criteria, $request ) {
if ( null === $error && isset( $criteria['von-zimmer'] ) && (float) $criteria['von-zimmer'] > 20 ) {
return new WP_Error( 'zu_viele_zimmer', 'Please check the number of rooms.' );
}
return $error;
}

If your filter always returns null, you also switch off the built-in check for contradictory ranges.

A complete, categorized overview of all available filter and action hooks can be found at Filter & Action Hooks.