Custom Fields with the epl_listing_meta_boxes filter

With Easy Property Listings you can create complete extra sections to your listings much like using Advanced Custom Fields plugin. However this is offers greater performance when adding a lot of extra details to listings.

Using a custom plugin instead of your theme functions file is a better solution to customising Easy Property Listings.

Custom Meta Fields with Easy Property Listings

The code below will produce the above image on your listings.

function my_add_meta_box_epl_listings_advanced_callback($meta_fields) {
	$custom_field = array(
		'id'		=>	'epl_property_listing_custom_data_id',
		'label'		=>	__('Custom Details', 'epl'), // Box header
		'post_type'	=>	array('property', 'rural', 'rental', 'land', 'commercial', 'commercial_land', 'business'), // Which listing types these will be attached to
		'context'	=>	'normal',
		'priority'	=>	'default',
		'groups'	=>	array(
			array(
				'id'		=>	'property_custom_data_section_1',
				'columns'	=>	'2', // One or two columns
				'label'		=>	'custom property data 1',
				'fields'	=>	array(
					array(
						'name'		=>	'property_custom_data_text',
						'label'		=>	__('custom property data', 'epl'),
						'type'		=>	'text',
						'maxlength'	=>	'150',
						'help'		=>	'Help text',
					),
					array(
						'name'		=>	'property_custom_data_radio',
						'label'		=>	__('custom property data Radio Options', 'epl'),
						'type'		=>	'radio',
						'opts'		=>	array(
								'option_1'	=>	'Option 1',
								'option_2'	=>	'Option 2',
								'option_3'	=>	'Option 3',
							),
						'help'		=>	'Radio help text',
					),
					array(
						'name'		=>	'property_custom_data_checkbox_single',
						'label'		=>	__('Checkbox Single', 'epl'),
						'type'		=>	'checkbox_single',
						'opts'		=>	array(
							'yes'	=>	__('Yes', 'epl'),
						)
					),
					
					array(
						'name'		=>	'property_custom_data_checkbox_multiple',
						'label'		=>	__('Checkbox Multiple', 'epl'),
						'type'		=>	'checkbox',
						'opts'		=>	array(
							'red'	=>	__('Red', 'epl'),
							'green'	=>	__('Green', 'epl'),
							'blue'	=>	__('Blue', 'epl'),
						)
					)
				)
			),
			
			array(
				'id'		=>	'property_custom_data_section_2',
				'columns'	=>	'2', // One or two columns
				'label'		=>	'custom property data 2',
				'fields'	=>	array(
					array(
						'name'		=>	'property_custom_data_select',
						'label'		=>	__('Custom Select', 'epl'),
						'type'		=>	'select',
						'opts'		=>	array(
								'select_1'	=>	'Select 1',
								'select_2'	=>	'Select 2',
								'select_3'	=>	'Select 3',
							),
					),
					
					array(
						'name'		=>	'property_custom_data_decimal',
						'label'		=>	__('Custom Decimal', 'epl'),
						'type'		=>	'decimal',
						'maxlength'	=>	'50'
					),
					
					array(
						'name'		=>	'property_custom_data_number',
						'label'		=>	__('Custom Number', 'epl'),
						'type'		=>	'number',
						'maxlength'	=>	'50'
					),
					
					array(
						'name'		=>	'property_custom_data_date',
						'label'		=>	__('Custom Date', 'epl'),
						'type'		=>	'date',
						'maxlength'	=>	'100'
					),
					
					array(
						'name'		=>	'property_custom_text_area',
						'label'		=>	__('Custom Text Area', 'epl'),
						'type'		=>	'textarea',
						'maxlength'	=>	'500'
					)
				)
			),
			array(
				'id'		=>	'property_custom_data_section_3',
				'columns'	=>	'1', // One or two columns
				'label'		=>	'',
				'fields'	=>	array(


					array(
						'name'		=>	'property_custom_editor',
						'label'		=>	__('Custom Editor', 'epl'),
						'type'		=>	'editor',
					)
				)
			)
		)
	);
	$meta_fields[] = $custom_field;
	return $meta_fields;
}
add_filter( 'epl_listing_meta_boxes' , 'my_add_meta_box_epl_listings_advanced_callback' );

To use the various fields that you create can be done using the global $property variable combined with the get_property_meta( $your_key ) function.

While using plugins to add additional meta fields is nice and in a GUI it is much slower than hard coding as per the example above as this requires minimal SQL database requests. This allows you to add many additional fields with little impact to your website speed.

How to use a text field

function my_custom_text_field_callback() {
	global $property;
	$custom_text_field = $property->get_property_meta('property_custom_data_text');
	if ( isset($custom_text_field) ) {
		echo $custom_text_field;
	}
}
// Add after the_content of the listing
add_action( 'epl_property_content_after' , 'my_custom_text_field_callback' );

How to use a radio field

The radio field requires options to be set depending on what you want to achieve.

function my_custom_radio_field_callback() {
	global $property;
	$custom_number_field = $property->get_property_meta('property_custom_data_number');
	if ( isset($custom_number_field ) ) {
		echo $custom_number_field;
	}
}
// Add after the_content of the listing
add_action( 'epl_property_content_after' , 'my_custom_radio_field_callback' );<br>

How to use a number field

The number formatting is already taken care of when entering data and you can use the 'number' or 'decimal' to control what the user can enter on a listing.

function my_custom_number_field_callback() {
	global $property;
	$custom_number_field = $property->get_property_meta('property_custom_data_number');
	if ( isset($custom_number_field ) ) {
		echo $custom_number_field;
	}
}
// Add after the_content of the listing
add_action( 'epl_property_content_after' , 'my_custom_number_field_callback' );

How to use options or select fields

This is where you should define your options outside of the meta so you can use them in the output function.

In the big example above you can see this section:

array(
	'name'		=>	'property_custom_data_select',
	'label'		=>	__('Custom Select', 'epl'),
	'type'		=>	'select',
	'opts'		=>	array(
		'select_1'	=>	'Select 1',
		'select_2'	=>	'Select 2',
		'select_3'	=>	'Select 3',
	),
),

But lets say you want to display the 'Select 1' (value) and not the option 'select_1' (key). This is where you can store your options in a custom function and display the value.

function my_custom_select_options() {

	$options = array(
		'key_select_1'	=>	'Value Select 1',
		'key_select_2'	=>	'Value Select 2',
		'key_select_3'	=>	'Value Select 3',
	);
	return $options;
}
Now you would adjust
'opts'	=>	array(
		'select_1'	=>	'Select 1',
		'select_2'	=>	'Select 2',
		'select_3'	=>	'Select 3',
	), 
// to be 
'opts' => my_custom_select_options(),
function my_custom_select_field_callback() {
	global $property;

	$array = my_custom_select_options(); // Save your options in a variable.
	$key = $property->get_property_meta('property_custom_data_select');

	$value = array_key_exists( $key , $array ) && !empty( $array[$key] )  ? $array[$key] : '';

	echo $value;
}
// Add after the_content of the listing
add_action( 'epl_property_content_after' , 'my_custom_select_field_callback' );