Support Forum
Hi, I have a custom post type (attraction) with a text field (att_address) and an OpenStreetMap field (att_osm).
I set this in Views to query posts:
{% set args = { post_type: "attraction", category_name: post.slug } %}
{% set posts = mb.get_posts( args ) %}
{% for key, post in posts %}
<h3>{{ post.post_title }}</h3>
<p><strong>Address: </strong>{{ post.att_address }}</p>
<a href="{{ mb.get_permalink( post.ID ) }}">Read More</a>
{% endfor %}
I would like to have a map with all the markers of the posts from this query but I really don't have any idea how to do it.
Please help!
Thank you!
Hi,
Please follow this article to know how to display many locations in map with some code https://metabox.io/display-all-listings-on-a-map/.
Hope it helps.
Hi, thank you for your link. I read it but it is for showing all the posts and using a template which not what I need.
I need many views to show separate posts depend on many conditions. In this case, they are location and types of attractions (at least).
I use these views as a part in many pages and posts, not for a page with template layout. So I need shortcode of Views to put them in places I want.
For ex: I have attractions in Madrid, Paris, Rome... With the query above, I can show attractions for each city, not all attractions on one page. And I would like to have a map for each city as well.
Thanks
Hi,
You can use the view as the template with the HTML code
<div id="map" style="width: 100%; height: 600px"></div>
and change the query to show locations base on a category (taxonomy) https://share.getcloudapp.com/bLujjb7j.
$query = new WP_Query( [
'post_type' => 'restaurant',
'tax_query' => [
[
'taxonomy' => 'custom_category', // taxonomy name
'field' => 'term_id', // term_id, slug or name
'terms' => 48, // term id, term slug or term name
]
]
] );
You can follow this topic to get more information about the query for custom taxonomy https://wordpress.stackexchange.com/questions/84921/how-do-i-query-a-custom-post-type-with-a-custom-taxonomy.