You add fields to the listing form of each post type in GeoDirectory under Places > Settings > Custom Fields (or the same screen for your other post types). The panel on the right has the field types you can add:
- Standard Fields are the basic input types, such as text, textarea, select, checkbox, date and file upload.
- Predefined Fields are ready made fields with sensible settings, such as Business Hours, Contact Email, Website, Facebook, X, Price and Video.
- A third group, Custom Fields, only appears when a plugin or snippet adds fields to it.
Click a field type, fill in its label and settings, and save. Drag fields in the list on the left to change their order on the form. See How to add a custom field to a custom post type for a walk through.
Add your own predefined field
If you add the same field to many sites or post types, you can add it to the Predefined Fields list with the geodir_custom_fields_predefined filter. This example adds a LinkedIn URL field:
add_filter( 'geodir_custom_fields_predefined', 'my_gd_predefined_fields', 10, 2 );
function my_gd_predefined_fields( $custom_fields, $post_type ) {
$custom_fields['linkedin'] = array(
'field_type' => 'url',
'class' => 'gd-linkedin',
'icon' => 'fab fa-linkedin',
'name' => 'LinkedIn',
'description' => 'Adds a LinkedIn URL input.',
'defaults' => array(
'data_type' => 'TEXT',
'admin_title' => 'LinkedIn',
'frontend_title' => 'LinkedIn',
'frontend_desc' => 'Enter your LinkedIn page URL.',
'htmlvar_name' => 'linkedin',
'is_active' => true,
'for_admin_use' => false,
'default_value' => '',
'show_in' => '[detail]',
'is_required' => false,
'option_values' => '',
'validation_pattern' => '',
'validation_msg' => '',
'required_msg' => '',
'field_icon' => 'fab fa-linkedin',
'css_class' => '',
'cat_sort' => false,
'cat_filter' => false,
),
);
return $custom_fields;
}
The array key and htmlvar_name must be unique and contain no spaces. field_type is one of the standard field types, and the defaults are the settings the field starts with when you add it, which you can still change afterwards. The $post_type argument lets you add a field for one post type only.
Add the snippet with the Code Snippets plugin, then reload the Custom Fields screen and the new field is in the Predefined Fields list.