listing Archives - WP Maps Pro

15000+ live websites are using this google maps wordpress plugin.

Hook Category: listing

The wpgmp_sorting hook in the WP Maps Pro plugin allows developers to customize the sorting options for the listings displayed below the map. This hook is triggered whenever the sorting functionality needs to be rendered or modified, enabling developers to adjust sorting behavior at runtime.

Usage

Developers can implement this hook within their theme’s functions.php file or a custom plugin. It is useful for altering the default sorting options provided by WP Maps Pro, adding new sorting criteria, or modifying existing ones. This hook accepts two parameters: $sorting_array, which is an array of current sorting options, and $map, which contains map-specific information.

Example 1

This example demonstrates how to add a new sorting option based on a custom field called “Distance”.

add_filter('wpgmp_sorting', 'custom_sorting_options', 10, 2);
function custom_sorting_options($sorting_array, $map) {
    $sorting_array['distance__asc'] = 'Nearest First';
    $sorting_array['distance__desc'] = 'Farthest First';
    return $sorting_array;
}

Example 2

In this example, we modify the label of an existing sorting option for the address in ascending order.

add_filter('wpgmp_sorting', 'modify_sorting_label', 10, 2);
function modify_sorting_label($sorting_array, $map) {
    if(isset($sorting_array['address__asc'])) {
        $sorting_array['address__asc'] = 'Address A-Z (Modified)';
    }
    return $sorting_array;
}

Example 3

This example illustrates how to remove a sorting option, specifically the “Z-A Title” option.

add_filter('wpgmp_sorting', 'remove_sorting_option', 10, 2);
function remove_sorting_option($sorting_array, $map) {
    unset($sorting_array['title__desc']);
    return $sorting_array;
}

Tip: Always ensure that your modifications do not conflict with other plugins or themes. Test changes in a staging environment before applying them to a live site to maintain the stability and security of your website.

The wpgmp_listing hook in the WP Maps Pro plugin allows developers to modify the settings of the listing displayed below the map. This hook provides a way to customize the appearance and functionality of location listings dynamically.

Usage

Developers can implement this hook in their WordPress theme or plugin to override or customize the listing settings at runtime. It is particularly useful for tailoring the user experience by adjusting how location data is presented or filtering options are applied.

Example 1

Modify the default number of locations displayed per page in the listing.

add_filter('wpgmp_listing', 'custom_listing_per_page', 10, 2);
function custom_listing_per_page($listing_settings, $map) {
    $listing_settings['pagination']['listing_per_page'] = '5';
    return $listing_settings;
}

Example 2

Enable the search form and category filter for the listing below the map.

add_filter('wpgmp_listing', 'enable_search_and_category_filter', 10, 2);
function enable_search_and_category_filter($listing_settings, $map) {
    $listing_settings['display_search_form'] = true;
    $listing_settings['display_category_filter'] = true;
    return $listing_settings;
}

Example 3

Change the default sorting option to sort by category in descending order.

add_filter('wpgmp_listing', 'modify_default_sorting_option', 10, 2);
function modify_default_sorting_option($listing_settings, $map) {
    $listing_settings['default_sorting'] = array('orderby' => 'category', 'inorder' => 'desc');
    return $listing_settings;
}

Tip: Always ensure that the modifications to the listing settings are thoroughly tested to provide a seamless user experience and to avoid any conflicts with other plugins or theme functionalities.

This hook in the WP Maps Pro plugin allows developers to modify the HTML of listing items displayed below the map. It provides flexibility to change how listings are presented by altering the HTML structure dynamically.

Usage

Developers can implement this hook in their theme’s functions.php file or in a custom plugin to change the layout or content of the listing items. By hooking into this filter, you can customize the output by modifying the HTML structure or adding additional data to the listings.

Example 1

This example demonstrates how to add a custom CSS class to the listing items for styling purposes.

add_filter('wpgmp_listing_html', 'custom_listing_html_class', 10, 2);
function custom_listing_html_class($html, $map) {
    return str_replace('<div class="listing-item">', '<div class="listing-item custom-class">', $html);
}

Example 2

In this example, we append additional information, such as a contact number, to each listing item.

add_filter('wpgmp_listing_html', 'append_contact_info', 10, 2);
function append_contact_info($html, $map) {
    $contact_info = '<p>Contact: 123-456-7890</p>';
    return $html . $contact_info;
}

Example 3

This example shows how to conditionally modify the listing HTML based on the category display format.

add_filter('wpgmp_listing_html', 'conditional_html_modification', 10, 2);
function conditional_html_modification($html, $map) {
    global $wpgmp_categorydisplayformat;
    if ($wpgmp_categorydisplayformat == 'grid') {
        $html = '<div class="grid-item">' . $html . '</div>';
    }
    return $html;
}

Tip: Always sanitize and validate any data before displaying it in the HTML to prevent security vulnerabilities such as XSS (Cross-Site Scripting).

Install Plugin Now!

Buy this plugin exclusively on CodeCanyon! You’ll get free updates, full support, and if you’re not satisfied, we’ve got you covered with a 30-day money-back guarantee.