How to add a custom field to an existing metabox on the edit listing page
You can easily add additional fields to existing meta boxes when editing a listing in the dashboard.
This is based on the filter epl_meta_groups_{group_id}
Available metabox groups names
- property_heading
- listing_agents
- listing_type
- display_details
- house_features
- land_details
- internal
- external
- heating_cooling
- address_block
- pricing
- sale_details
- rental_pricing
- rural_features
- commercial_leasing
- tenant_n_outgoings
- commercial_features
- business_categories
- files_n_links
- files_n_links_2
- owner_details
Register your new field to the pricing meta box
<?php
/**
* Add custom text field in pricing section
* @uses EPL Filter epl_meta_groups_{group_id}
*/
function my_epl_add_pricing_fields($group) {
$group['fields'][] = array(
'name' => 'my_custom_field',
'label' => __('Custom Field', 'easy-property-listings' ),
'type' => 'text',
);
return $group;
}
add_filter('epl_meta_groups_pricing', 'my_epl_add_pricing_fields');
Register multiple fields
<?php
/**
* Add custom text field in pricing section
* @uses EPL Filter epl_meta_groups_{group_id}
*/
function my_epl_add_multiple_pricing_fields($group) {
$group['fields'][] = array(
'name' => 'property_pricing_class',
'label' => __( 'Pricing Class', 'easy-property-listings' ),
'type' => 'text',
);
$group['fields'][] = array(
'name' => 'property_tenancy',
'label' => __( 'Tenancy', 'easy-property-listings' ),
'type' => 'text',
);
return $group;
}
add_filter('epl_meta_groups_pricing', 'my_epl_add_multiple_pricing_fields');
Display your new field
<?php
function my_custom_text_field_callback() {
global $property;
$custom_text_field = $property->get_property_meta('my_custom_field');
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' );
Add the field before other fields in the same group
<?php
/**
* Add custom text field before other fields
* @uses EPL Filter epl_meta_groups_{group_id}
*/
function my_epl_add_house_age_fields( $group ) {
$new_fields['fields'] = array(
'name' => 'my_custom_field',
'label' => __('Custom Field', 'easy-property-listings' ),
'type' => 'text',
);
$group['fields'] = $new_fields + $group['fields'];
return $group;
}
add_filter( 'epl_meta_groups_house_features', 'my_epl_add_house_age_fields' );