Total number of markers in shortcode

New home Forums Visitor Generated Markers Total number of markers in shortcode

  • This topic has 5 replies, 2 voices, and was last updated 2 weeks ago by Matthew.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #70448
    nuances
    Participant

    Hi,

    Is there a way to show the total number of markers by use of a shortcode?

    That would really be awesome.

    Thanx!

    #70449
    Matthew
    Moderator

    Hi there,

    Thank you for getting back in touch with us, we do appreciate your time.

    Unfortunately, we do not have a shortcode that displays the number of markers on a map, however, this can be achieved using some custom JS code (Maps -> Settings -> Advanced Settings).

    With that said, the respective custom JS code that can be used is as follows:

    jQuery(function($){
       $(document).on('markersplaced.wpgmza', function(){
          const totalMarkers = WPGMZA.maps[0].markers.length;
          $('<h4 class="wpgmza_number_of_markers">Number of markers on the map: ' + totalMarkers + '</h4>').insertAfter('.wpgmza_map');
       }); 
    })

    The above custom JS code will display text below your map container showing how many markers are on the map.

    Please do let me know if this helps and answers your question?

    Kindest Regards,
    Matthew

    #70455
    nuances
    Participant

    Hi Matthew,

    Thanx for getting back to me this quick.

    As for the number of markers:
    I am happy to see that there is a possibility to show the number of markers.
    However, it would be so great to have a way (not specifically with shortcode, maybe via another way) to be able to show the number of markers in a span or something like that.
    The reason for this: we launched an event that went viral on national news resulting in many people placing markers as a sort of growing community. Therefore, if the number of markers continuesly increases (for instance showing on the homepage to create that community-feeling). We are also planning to show the number of markers on big screens in town to create even more awareness.
    So if there would be a way to show the number of markers outside the map, it would really be awesome!

    Another question:
    Is it possible to redirect a user to another URL once the marker is placed?

    Looking forward to your answer(s).

    Best regards, Maurice.

    #70473
    Matthew
    Moderator

    Hi Maurice,

    Thank you for your response and time on this, I really appreciate it!

    If you are wanting to retrieve the number of markers on the map externally, this functionality is not supported. However, you can display the number of markers on the map and then hide the map so that only the span is displayed.

    There are ways to get the number of markers on the map externally, however, this falls under customization work, which we currently do not have the capacity to take on at this stage.

    An idea of how this could be done is to get the number of records of markers in your database using SQL code. Alternatively, you could make use of the markers endpoint whereby you can use some code to get the number of markers in the endpoint. The marker REST endpoint would be: https://www.example.com/wp-json/wpgmza/v1/markers

    With regards to redirecting users to a different URL once they have submitted a marker, yes this is possible using the redirect_to VGM form shortcode parameter. More information on this can be seen here: https://www.wpgmaps.com/documentation/advanced-map-options/map-shortcode-parameters/#VGM_form

    I hope this answers your question?

    Kindest Regards,
    Matthew

    #70477
    nuances
    Participant

    Hi Matthew,

    Ok, thanx for your clear reply.
    The redirect works like a charm!

    And as for the number of markers: yeah, indeed I have given it a thought via hiding classes, etc. But I was hoping for a somewhat easier solution should it have excisted 😉

    Thanx!
    Cheers, Maurice.

    #70478
    Matthew
    Moderator

    Hi Maurice,

    That is fantastic news, I am happy to hear that it is working like a charm.

    Unfortunately we do not have an easier solution than hiding classes, however, we may look into this in the future.

    Should you require any further assistance, we are more than happy to help.

    Kindest regards,
    M

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.