wpgmp_map_supported_post_types - WP Maps Pro

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

wpgmp_map_supported_post_types

This hook in WP Maps Pro allows developers to modify the list of post types that are considered when querying for posts with assigned locations. It is triggered during the process of optimizing queries to improve performance by excluding unnecessary post types.

Usage

Developers can implement this hook in their theme’s functions.php file or a custom plugin. It helps in customizing the set of post types to be included or excluded based on specific requirements.

Example 1

Exclude a custom post type ‘event’ from being queried for location data.

add_filter('wpgmp_map_supported_post_types', function($all_post_types, $map) {
    if(($key = array_search('event', $all_post_types)) !== false) {
        unset($all_post_types[$key]);
    }
    return $all_post_types;
}, 10, 2);

Example 2

Include a custom post type ‘property’ in the list of post types being queried for location data.

add_filter('wpgmp_map_supported_post_types', function($all_post_types, $map) {
    if(!in_array('property', $all_post_types)) {
        $all_post_types[] = 'property';
    }
    return $all_post_types;
}, 10, 2);

Example 3

Restrict the query to only ‘post’ and ‘page’ post types, ignoring all others.

add_filter('wpgmp_map_supported_post_types', function($all_post_types, $map) {
    return array_intersect($all_post_types, ['post', 'page']);
}, 10, 2);

Tip: Always ensure that you test the hook implementation in a staging environment before deploying to a live site to avoid unexpected issues.

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.