Release 2.6.0
Version 2.6.0 adds the option to query maps: This allows you to create a map consisting of other maps, added on other posts or post types. This can be quite powerful when, for example, you have a custom post type for "Places" with each place having its own map, and you want to dynamically gather-up all the places on a single map. A shortcode has also been added as an alternative way to use this feature.
FAQ
How can I query maps from other posts or post types?
On the block's side panel, Select the "Map data" panel and click on the "Fetch locations" button. This will automatically retrieve on the frontend all the markers from your posts (you can also select a specific post type from the dropdown). The block will be locked from editing, as the markers will be dynamically retrieved from the selected posts. If you don't want that, there is a "Stop syncing" button that will unlock the block, drop the markers on the map and allow you to edit.
How can I use the shortcode?
The shortcode [ootb_query]
allows you to display a dynamic map, which retrieves markers from other posts or post types. Just add it to a post or page and you're good to go. By default, it will fetch the markers from the 100 most recent posts. The shortcode supports the following attributes:
- post_type: (Optional) The type of post to query. By default, it is set to
post
. - posts_per_page: (Optional) The number of posts to be displayed on page. Default value is
100
. - post_ids: (Optional) Comma-separated IDs of the posts to include in the query.
- height: (Optional) The desired height for the map. Default value is empty, which falls back to
400px
. - provider: (Optional) Specifies the map provider. Options are:
openstreetmap
,mapbox
andstamen
. The default value is an empty string which falls back toopenstreetmap
. - maptype: (Optional) Specifies the type of map. Options are:
markers
,polygon
andpolyline
. The default value is an empty string, which will fall back tomarkers
. - touchzoom: (Optional) If set, touch zoom will be enabled on the map. It can be either
true
orfalse
. The default value is an empty string, which falls back totrue
. - scrollwheelzoom: (Optional) If set, enables zooming on the map with mouse scroll wheel. It can be either
true
orfalse
. The default value is an empty string, which falls back totrue
. - dragging: (Optional) If set, dragging is enabled on the map. It can be either
true
orfalse
. The default value is an empty string, which falls back totrue
. - doubleclickzoom: (Optional) If set, allows zooming in on the map with a double click. It can be either
true
orfalse
. The default value is an empty string, which falls back totrue
. - marker: (Optional) Specifies the marker for the map. This should correspond to the URL of the image that you want to use as the marker's icon (example:
https://www.example.com/my-custom-icon.png
). The default value is an empty string, which retrieves the default marker.
Here's an example of how you can use it:
[ootb_query post_type="post" post_ids="1,2,3,4" height="400px" provider="mapbox" maptype="polygon" touchzoom="true" scrollwheelzoom="true" dragging="true" doubleclickzoom="true" marker="https://www.example.com/my-custom-icon.png"]
I want more control. Are there any hooks that I could use?
Glad you asked! There are a few hooks that you can use to further customize the plugin's behavior. Here they are:
ootb_query_post_type
: Allows you to change the post type that the plugin will query for markers. By default, it is set topost
. You can pass multiple post types as an array. Example:
add_filter( 'ootb_query_post_type', function() { return array( 'post', 'page' ); } );
ootb_query_posts_per_page
: Allows you to change the number of posts that the plugin will query for markers. By default, it is set to100
. Example:
add_filter( 'ootb_query_posts_per_page', function() { return 500; } );
ootb_query_extra_args
: Allows you to add extra arguments to the query that the plugin will use to retrieve markers. By default, it is set to an empty array. Example:
add_filter(
'ootb_query_extra_args',
function() {
return [
'tax_query' => [
[
'taxonomy' => 'people',
'field' => 'slug',
'terms' => 'bob'
]
];
}
);
Keep in mind that the extra args will be merged with the default ones, so you don't have to worry about overriding them. In fact, the args that are required for the query to work, cannot be overridden.