epl_listing_meta_boxes Filter

How to add custom meta fields to the edit listing pages using the epl_listing_meta_boxes filter

Easy Property Listings includes a filter which allows you to add your own custom fields to your listings.

function my_add_meta_box_epl_listings_callback($meta_fields) {
	$custom_field = array(
			'id'		=>	'epl-property-listing-custom-data-id',
			'label'		=>	__('Custom Details', 'epl'),
			'post_type'	=>	array('property', 'rural', 'rental', 'land', 'commercial', 'commercial_land', 'business'),
			'context'	=>	'normal',
			'priority'	=>	'default',
			'groups'	=>	array(
					'id'		=>	'property_custom_data_section',
					'columns'	=>	'1',
					'label'		=>	'custom property data',
					'fields'	=>	array(
							'name'		=>	'property_custom_data',
							'label'		=>	__('custom property data', 'epl'),
							'type'		=>	'text',
							'maxlength'	=>	'150'
						), // Repeat for more fields.
	$meta_fields[] = $custom_field;
	return $meta_fields;
add_filter( 'epl_listing_meta_boxes' , 'my_add_meta_box_epl_listings_callback' );

This code will output on your listings pages.

Then you can output the field onto your template using a custom function.

Any additional meta fields that you add are saved into the global $property; variable. So no need to use get_post_custom() which is slower as the values are already saved in the global $property variable.

function my_property_custom_data() {
	global $property;
	// Get the custom variable
	$custom_data	= $property->get_property_meta( 'property_custom_data' );
	if ( isset ($custom_data) ) {
		// Echo the custom variable if there is a value. You can wrap in a span tag.
		echo '<span class="custom-class">' . $custom_data . '</span>';
// This will echo the custom variable beside the price
add_action( 'epl_property_price' , 'my_property_custom_data' , 9 );

You can place the data anywhere using the various hooks available in the template. Each template has several do_action sections. In the example above replace the epl_property_price with the do_action function which you can find from the links below.

Single Listing Template on GitHub

Archive Listing Template on GitHub