I have a map linked to an toolset image field where it uses a coloured pin to display on the map depending on which category they belong to. Red pin for Category 1 and Blue for Category 2. I would like to automate this process if possible.
The link to the actual map page is hidden link
I have a category set up named Membership Types with taxonomies set up as Category 1 and Category 2.
And an toolset image field set up named map-pin which I then use an image named pin-cat1.png image for Category 1 and pin-cat2.png image for Category 2
What I would like to happen is that when they belong to the Category 1 the toolset map-pin field automatically chooses the image pin-cat1.png and then if they belong to Category 2 the toolset map-pin field automatically chooses the image pin-cat2.png
Can I check how you've done this so far? Looking at the page I would have expected this to be created using a View (and my question would be whether you were using the legacy Views editor or the block editor), but checking the source markup it doesn't look like you've used a Toolset View or a Toolset Map at all, and are using some other solution altogether.
So I'm not clear what you need, as I don't know how this is set up, how you are adding markers to a map, and how you are currently setting some of those to red, and others to blue.
I have used a separate search and filter plugin with dynamic.ooo google map widget rather than using view as it did not allow for all the functionality I required. The google map widgets allows me to choose an image from a acf or toolset field.
But what I really want is for my toolset field I have set up called map-pin to choose the correct image based on the category type that was chosen eg Category 1 or Category 2. The plugin that I then use for the map will then have the correct image already chosen to use for the map.
So if I can get toolset to populate the following
Membership type Category 1 is selected - this then populate the map-pin field with the image pin-cat1.png
Membership type Category 2 is selected - this then populate the map-pin field with the image pin-cat2.png
To help with this, can you describe when/how the data is entered?
If you are adding posts (that will appear on the map) and these posts should have a custom field set to the marker image—depending on the category—then it seems like the time the post is published is the time to intervene and set the field value as required.
If you are using a Toolset form to publish posts from the front end that's easy enough, using the Forms API hooks.
If using some other method you may need something else.
I've drafted some sample code that you can modify for your needs. It starts by defining a number of variables that would be specific to your site, and if you set those right I think it should work, but naturally I'm not in a position to test.
Writing custom code is outside the scope of support, and while I hope it meets your needs, if not you may need to contact a developer to produce a working solution.
function ts_set_marker_icon( $post_id, $post, $update ){
$post_type = 'profile'; // post type this code should apply to
$field_key = 'wpcf-marker-icon'; // custom field to store icon url, note Toolset fields include a 'wpcf-' prefix
$marker1 = '<em><u>hidden link</u></em>'; // URL of marker for category 1
$marker2 = '<em><u>hidden link</u></em>'; // URL of marker for category 2
$taxonomy = 'membership-type'; // slug of taxonomy that stores the category
$term1 = 'one'; // slug of the term for category 1
$term2 = 'two'; // slug of the term for category 2
if ( $post->post_type != $post_type )
return;
// What is the category value of this post?
$categories = get_the_terms( $post_id, $taxonomy );
if ( $categories ) {
$category = $categories[0]; // it should only have one category
if ( $category->slug == $term1 ) {
update_post_meta( $post_id, $field_key, $marker1 );
} elseif ( $category->slug == $term2 ) {
update_post_meta( $post_id, $field_key, $marker2 );
}
}
}
add_action( 'save_post', 'ts_set_marker_icon', 10, 3 );