filters Archives - WP Maps Pro

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

Hook Category: filters

The wpgmp_query_posts_array hook in WP Maps Pro allows developers to customize the query used to fetch posts that have a location assigned through custom fields. It is triggered when the map is generated and needs to query posts with location data.

Usage

Developers can implement this hook within their theme’s functions.php file or within a custom plugin. This hook is particularly useful for modifying the query to include additional criteria or to alter the default behavior of how posts with location data are fetched. To use this hook effectively, understand the data structure and parameters it accepts.

Example 1

This example demonstrates how to modify the query to only include posts from a specific category.

add_filter('wpgmp_query_posts_array', 'modify_posts_query_by_category', 10, 2);
function modify_posts_query_by_category($filter_array, $map) {
    if(isset($filter_array['post'])) {
        $filter_array['post']['category_name'] = 'specific-category';
    }
    return $filter_array;
}

Example 2

In this example, the query is adjusted to fetch posts within a certain date range.

add_filter('wpgmp_query_posts_array', 'filter_posts_by_date_range', 10, 2);
function filter_posts_by_date_range($filter_array, $map) {
    if(isset($filter_array['post'])) {
        $filter_array['post']['date_query'] = array(
            array(
                'after'     => 'January 1st, 2023',
                'before'    => 'December 31st, 2023',
                'inclusive' => true,
            ),
        );
    }
    return $filter_array;
}

Example 3

This example shows how to modify the query to include posts that are tagged with a specific custom field value.

add_filter('wpgmp_query_posts_array', 'filter_posts_by_custom_field', 10, 2);
function filter_posts_by_custom_field($filter_array, $map) {
    if(isset($filter_array['post'])) {
        $filter_array['post']['meta_query'] = array(
            array(
                'key'     => '_custom_field_key',
                'value'   => 'desired_value',
                'compare' => '=',
            ),
        );
    }
    return $filter_array;
}

Always ensure that the modifications you make using this hook are well-tested to prevent any unintended side effects. Proper validation and sanitization of inputs should be implemented to maintain security and performance.

This hook in WP Maps Pro allows developers to customize the functionality at runtime by changing the position of the filters container. It is specifically used to modify the data container identified by [data-container="wpgmp-filters-container"] and accepts parameters such as '[data-container="wpgmp-filters-container"]' and $map.

Usage

Developers can implement this hook in their WordPress themes or plugins to alter the position of the filters container dynamically. This can be particularly useful when needing to integrate WP Maps Pro with other components or when requiring custom layouts.

Example 1

In this example, the hook is used to append additional classes to the filters container, potentially for styling purposes.

add_filter( 'wpgmp_filter_container', 'customize_filters_container', 10, 2 );
function customize_filters_container( $container, $map ) {
    $container .= ' custom-class';
    return $container;
}

Example 2

This example demonstrates how to move the filters container to a different location in the DOM, by using JavaScript to reposition it.

add_filter( 'wpgmp_filter_container', 'move_filters_container', 10, 2 );
function move_filters_container( $container, $map ) {
    $container = "<script type='text/javascript'>
        document.addEventListener('DOMContentLoaded', function() {
            var filtersContainer = document.querySelector('[data-container=\"wpgmp-filters-container\"]');
            var newParent = document.getElementById('new-location');
            if (filtersContainer && newParent) {
                newParent.appendChild(filtersContainer);
            }
        });
    </script>";
    return $container;
}

Example 3

Here, the hook is used to inject custom content or HTML before the filters container, which might be useful for adding labels or instructions.

add_filter( 'wpgmp_filter_container', 'add_content_before_filters', 10, 2 );
function add_content_before_filters( $container, $map ) {
    $custom_content = '<div class="custom-content">Before Filters Content</div>';
    $container = $custom_content . $container;
    return $container;
}

Tip: Always ensure that any custom code or scripts added through hooks are thoroughly tested to prevent breaking the layout or functionality of the WP Maps Pro plugin. Additionally, consider using WordPress’s built-in security functions to sanitize and validate data.

The wpgmp_filters hook in WP Maps Pro allows developers to customize marker filtering functionalities at runtime. It is triggered to add or remove custom filters for marker filterings.

Usage

Developers can implement this hook in their WordPress themes or plugins to modify the available filtering options for map markers. This is particularly useful for tailoring the map’s filtering functionality to fit specific requirements or user preferences.

Example 1

In this example, we add a new custom filter for filtering markers by “Region”.

add_filter('wpgmp_filters', 'add_region_filter', 10, 2);
function add_region_filter($all_filters, $map) {
    // Ensure base structure exists
    if (!isset($all_filters['filters'])) {
        $all_filters['filters'] = [];
    }

    if (!isset($all_filters['filters']['dropdown'])) {
        $all_filters['filters']['dropdown'] = [];
    }

    // Add the Region filter
    $all_filters['filters']['dropdown']['region'] = 'Region';

    return $all_filters;
}

Example 2

This example demonstrates how to remove the “Phone” filter from the list of available filters.

add_filter('wpgmp_filters', 'remove_phone_filter', 10, 2);
function remove_phone_filter($all_filters, $map) {
    if (isset($all_filters['filters']['dropdown']['phone'])) {
        unset($all_filters['filters']['dropdown']['phone']);
    }
    return $all_filters;
}

Example 3

Here, we replace a placeholder with an actual taxonomy slug for a custom taxonomy filter.

add_filter('wpgmp_filters', 'custom_taxonomy_filter', 10, 2);
function custom_taxonomy_filter($all_filters, $map) {
    // Ensure the filters and dropdown keys exist
    if (!isset($all_filters['filters'])) {
        $all_filters['filters'] = [];
    }

    if (!isset($all_filters['filters']['dropdown'])) {
        $all_filters['filters']['dropdown'] = [];
    }

    // Add your custom taxonomy filter
    $all_filters['filters']['dropdown']['custom_taxonomy_slug'] = 'Custom Taxonomy';

    return $all_filters;
}

Tip: Always validate and sanitize the data you work with to maintain the security and integrity of your WordPress site.

This hook in WP Maps Pro allows developers to customize the functionality of displaying map locations at runtime. It is triggered when there is a need to filter or limit the locations shown on a map.

Usage

Developers can implement this hook in the functions.php file of their theme or within a custom plugin. It allows for dynamic modification of location display criteria, such as showing only certain categories of locations or limiting the number of locations shown.

Example 1

Limit the number of locations displayed on the map to 5.

add_filter('wpgmp_location_criteria', 'limit_locations_on_map', 10, 2);
function limit_locations_on_map($location_criteria, $map) {
    $location_criteria['limit'] = 5;
    return $location_criteria;
}

Example 2

Show only locations belonging to a specific category on the map.

add_filter('wpgmp_location_criteria', 'show_specific_category_locations', 10, 2);
function show_specific_category_locations($location_criteria, $map) {
    $location_criteria['category__in'] = array(3); // Replace 3 with your desired category ID
    return $location_criteria;
}

Example 3

Ensure all locations are displayed without any limitation or category filter.

add_filter('wpgmp_location_criteria', 'show_all_locations', 10, 2);
function show_all_locations($location_criteria, $map) {
    $location_criteria['show_all_locations'] = true;
    $location_criteria['category__in'] = false;
    $location_criteria['limit'] = 0;
    return $location_criteria;
}

Tip: Always validate and sanitize input data to ensure secure usage of hooks and prevent potential security vulnerabilities.

This hook in WP Maps Pro allows developers to customize the functionality of the category tab settings at runtime. It is triggered when the category tab data is being prepared, letting developers modify it as needed.

Usage

Developers can implement this hook in their themes or plugins to alter the default behavior of the category tab settings in WP Maps Pro. This can be done by adding a custom function to the hook, which can modify the data being passed through it. Practical tips include ensuring the data structure is maintained and validating any changes made to the data for compatibility.

Example 1

This example demonstrates modifying the category tab title.

add_filter('wpgmp_category_tab', 'customize_category_tab_title', 10, 2);
function customize_category_tab_title($category_tab, $map) {
    $category_tab['cat_tab_title'] = 'Custom Category Title';
    return $category_tab;
}

Example 2

This example shows how to change the order of categories by their ID instead of title.

add_filter('wpgmp_category_tab', 'order_categories_by_id', 10, 2);
function order_categories_by_id($category_tab, $map) {
    $category_tab['cat_order_by'] = 'id';
    return $category_tab;
}

Example 3

Here we demonstrate how to hide the “Select All” option in the category tab.

add_filter('wpgmp_category_tab', 'hide_select_all_option', 10, 2);
function hide_select_all_option($category_tab, $map) {
    $category_tab['select_all'] = 0;
    return $category_tab;
}

Always ensure that any modifications you make using this hook are thoroughly tested to prevent unexpected behavior and maintain compatibility with future updates of the WP Maps Pro plugin.

Install Plugin Now!

WP MAPS PRO helps you create dynamic, customizable maps using Google Maps or Leaflet — no coding required. Includes free updates, premium support, and a 30-day money-back guarantee.