wpsl_cpt_info_window_meta_fields

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

Description

This filter allows you to add data to the marker pop-up on individual store pages, and on maps made with the [wpsl_map] shortcode. The keys you add can be used in the wpsl_cpt_info_window_template.

In the search results and the store locator pop-up, fields you create in the Fields Manager are included automatically. That doesn’t happen yet for this pop-up, so add them with this filter.

The plugin adds more data after this filter runs, and those keys overwrite any value you set with the same name: the permalink or store URL, the coordinates, the ID and the marker images. The phone, fax, email, URL, post content and open / closed status are added as well when “The landing page marker pop-up” is selected for them under Settings > User Experience.

Parameters

$store_meta - (array) The location data for the pop-up: store, address, address2, city, state, zip and country. $store_id - (int) The ID of the store.

Usage

This example adds the value of a custom field called my_textinput under the my_textinput key. Fields are saved with a wpsl_ prefix, so the meta key is wpsl_my_textinput.

add_filter( 'wpsl_cpt_info_window_meta_fields', 'custom_cpt_info_window_meta_fields', 10, 2 );
function custom_cpt_info_window_meta_fields( $store_meta, $store_id ) {
/**
* Fields are saved with a 'wpsl_' prefix,
* so 'my_textinput' is stored as 'wpsl_my_textinput'.
*/
$store_meta['my_textinput'] = esc_html( get_post_meta( $store_id, 'wpsl_my_textinput', true ) );
return $store_meta;
}

The template prints the values as HTML, so escape them with esc_html(), or with esc_url() for a link.

To show the field in the pop-up, add it to the template with the wpsl_cpt_info_window_template filter. Check it with typeof there: if a location doesn’t have the field, the pop-up doesn’t open.

Changelog

VersionDescription
3.0Moved to includes/frontend/shortcodes/class-shortcodes.php. The contact details, post content and open / closed status are added after this filter when "The landing page marker pop-up" is selected for them.
2.0Introduced.

Source File

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

Placement

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