wpsl_frontend_meta_fields

  1. Description
  2. Parameters
  3. Usage
  4. Changelog
  5. Source File
  6. Related

Description

This filter allows you to add store meta data to the location data of the search results and the store locator marker pop-up. The fields you add can be used in the wpsl_listing_template, wpsl_more_info_template, wpsl_info_window_template and wpsl_store_header_template.

Fields you create under Store Locator > Settings > Fields Manager are included automatically, so you only need this filter for meta data that’s saved in another way, for example with the wpsl_meta_box_fields filter or by another plugin.

For the marker pop-up on store pages and [wpsl_map] maps, use wpsl_cpt_info_window_meta_fields instead.

Parameters

$store_fields - (array) The meta fields that are included in the location data. Each key is the meta key the value is saved under. Each value is an array with:

  • name - the key the value gets in the location data, and the name you use in the template.
  • type - optional, decides how the value is cleaned up. Without a type, it's treated as text.
TypeOutput
textPlain text, HTML is removed
textarea, wp_editorParagraphs, with the HTML that's allowed in post content
emailAn email address
phoneA phone number that's safe to use in a tel: link
urlA URL
numericA number, or 0 if the value isn't numeric

Usage

This example includes the value of the wpsl_my_textinput meta field in the location data, under the my_textinput key.

add_filter( 'wpsl_frontend_meta_fields', 'custom_frontend_meta_fields' );
function custom_frontend_meta_fields( $store_fields ) {
// Include the 'wpsl_my_textinput' meta field under the 'my_textinput' key.
$store_fields['wpsl_my_textinput'] = [
'name' => 'my_textinput',
'type' => 'text',
];
return $store_fields;
}

Fields added with the Fields Manager or wpsl_meta_box_fields are saved with a wpsl_ prefix, so a field called my_textinput has the meta key wpsl_my_textinput. For meta data from another plugin, use the meta key that plugin saves it under.

To show the field, add <%= my_textinput %> to one of the templates. See the wpsl_listing_template example, and check the field with typeof there.

After you add a field, clear the cache under Store Locator > Settings > Tools > Autoload cache.

Changelog

VersionDescription
3.0Moved to includes/frontend/store/class-data.php. Fields created in the Fields Manager are included automatically.
2.0Introduced.

Source File

This filter is located in /includes/frontend/store/class-data.php.

Placement

The code needs to be placed in the functions.php file inside your active theme folder.