Useful examples of applying filter hooks
WP-ImmoMakler® is equipped with numerous WordPress Filter and Action Hooks (see below for the full list), which allow you to change the output and import behavior from outside the plugin code.
We have listed some useful filters below. Copy the relevant code examples in the functions.php
of your Child Skin plugin under wp-content/plugins/immomakler-child/functions.php
and customize them to your needs. At your request we will specify the filters that best meet your needs.
Make custom field (post meta) available for queries
With WP-ImmoMakler® 5.8 and higher, not all real estate values are available as an individual post meta key to improve performance.
The following filters let you create individual post meta fields to make them available for meta 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;
}
Define selection fields in the search mask (taxonomies)
See below for available taxonomies.
add_filter('immomakler_search_enabled_taxonomies', 'my_immomakler_search_taxonomies');
function my_immomakler_search_taxonomies( $taxomonies ) {
return array(
'immomakler_object_vermarktung',
'immomakler_object_nutzungsart',
'immomakler_object_type',
'immomakler_object_location',
);
}
Define fields for the advanced search (post meta fields)
add_filter('immomakler_search_enabled_ranges', 'my_immomakler_search_ranges');
function my_immomakler_search_ranges( $ranges ) {
return array(
'immomakler_search_size' => array(
'label' => 'Wohnfläche',
'slug' => 'qm',
'unit' => 'm²',
'decimals' => 0,
'meta_key' => 'wohnflaeche',
'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
),
);
}
Define the standard sorting filters for the list view
add_filter('immomakler_default_order', 'custom_immomakler_default_order');
function custom_immomakler_default_order( $im_order ) {
return 'priceasc'; // möglich sind: 'priceasc', 'pricedesc', 'dateasc', 'datedesc'
}
Define the size of real estate images.
With 'crop' => true
, images can be cropped to the stated value. With 'crop' => false
, the stated value determines the borders.
add_filter('immomakler_image_sizes', 'custom_immomakler_image_sizes');
function custom_immomakler_image_sizes( $images_sizes ) {
$images_sizes['immomakler-archive-thumb'] = array( 'width' => 350, 'height' => 250, 'crop' => false );
return $images_sizes;
}
Standard sizes are:
array(
'immomakler-gallery-big' => array( 'width' => 900, 'height' => 900, 'crop' => false ),
'immomakler-gallery-thumb' => array( 'width' => 100, 'height' => 60, 'crop' => false ),
'immomakler-archive-thumb' => array( 'width' => 360, 'height' => 390, 'crop' => false ),
'immomakler-archive-thumb-big' => array( 'width' => 475, 'height' => 475, 'crop' => false ),
'immomakler-person-thumb' => array( 'width' => 190, 'height' => 190, 'crop' => false )
)
Set change date for real estate data updates to the current day.
A real estate object appears at the end of the list by default even after an update (date of the first publication on the website). Use this filter if you want it to appear at the top of the list after an update.
add_filter ('immomakler_preserve_post_date_on_update', '__return_false');
Generate country entry ‘Abroad’
Countries are generated as taxonomy by default and can be listed under URL /immobilien-in/spanien/
. You can use the following category for immobilien-in/ausland/
. You can define the primary country (not abroad) in the WP backend under ‘WP-ImmoMakler > Settings > Import’.
add_filter ('immomakler_mark_foreign_countries', '__return_true');
Customize the galleria.io options for the exposé slideshow
add_filter('immomakler_galleria_options', 'immomakler_custom_galleria_options');
function immomakler_custom_galleria_options( $options ) {
$options['transition'] = 'fade';
$options['autoplay'] = '3000';
return $options;
}
Creating your own object types
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;
}
Create custom usage types based on user-defined fields from the estate agent software
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;
}
Creating custom taxonomies
The following WordPress taxonomy example ‘immomakler_search_zip_code’ can be integrated, for instance, under ‘selection fields in the search mask’, as explained above, or used within a shortcode: [immomakler-archive vermarktungsart=kauf plz="12345,12355,12347"]
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' );
}
}