How to Use Custom Replacement Variables

With IDX+, you can use variables such as %%city%% that get replaced with the relevant information.

But what if you want a field that isn’t a default field, such as the name of the apartment complex? Often, this is defined as Tract (accessible using `%%tract%%`).

Add the following code to your active theme’s `functions.php` file.

Add one replacement variable

add_filter('the_content', 'add_complex_park_to_idx_data', 21);

function add_complex_park_to_idx_data($content) {
	global $wp;

	if(!empty($wp->idx_plus)) {
		$supplemental = IDX_Plus::get_global('supplemental');

		if($supplemental && isset($supplemental['Complex/Park'])) {
			$wp->idx_plus['complex'] = $supplemental['Complex/Park'];
		}
	}

	return $content;
}

Add all available replacement variables

This piece of code will make all data in the Additional Details section available using replacement variables. If there is a field named “Master Bedroom Dimensions,” it will be available using `%%master-bedroom-dimensions%%`.

add_filter('the_content', 'add_supplemental_data_to_idx_data', 22);

function add_supplemental_data_to_idx_data($content) {
	global $wp;

	if(!empty($wp->idx_plus)) {
		$supplemental = IDX_Plus::get_global('supplemental');

		if($supplemental) {
			foreach($supplemental as $key => $value) {
				$wp->idx_plus[sanitize_title($key)] = $value;
			}
		}
	}

	return $content;
}

You can use these custom variables in any part of your template and it will be replaced.

Tags: ,

Comments are closed.