• 3stripe

    (@3stripe)


    Have added the following to my functions.php file as a proof of concept, as I have 1 placemarker which assisgned only to my ‘shop’ category:

    function setBGMPDefaultIconByCategory( $iconURL, $placemarkID )
    {
        $placemarkCategories = wp_get_object_terms( $placemarkID, 'bgmp-category' );
    
        foreach( $placemarkCategories as $pc )
            if( $pc->slug == 'shop' ) {
                $iconURL = 'https://www.gravatar.com/avatar/1cf0770522223715996d00a7fe911003?s=48&d=monsterid&r=g';
    		} else {
    			$iconURL = get_bloginfo( 'stylesheet_directory' ) . '/img/map_marker_generic.png';
    		}
        return $iconURL;
    }
    add_filter( 'bgmp_default-icon', 'setBGMPDefaultIcon', 10, 2);

    No markers at all are showing on my map, and I’m getting error messges for each placemark:

    bgmp_createMarker(): Postname icon wasn't passed in.

    I’ve tried disabling all other plugins and switching to default theme.

    Running locally on MAMP but can upload if it helps.

    Guess I must be missing something obvious?

    https://www.ads-software.com/extend/plugins/basic-google-maps-placemarks/

Viewing 15 replies - 1 through 15 (of 15 total)
  • Thread Starter 3stripe

    (@3stripe)

    PS. Some of my places are assigned to multiple categories.

    Plugin Author Ian Dunn

    (@iandunn)

    This might not be the only problem, but I’m pretty sure you’ll need curly braces around the foreach... loop.

    Thread Starter 3stripe

    (@3stripe)

    Thanks for the heads up! (I copied that text from your readme btw)

    It must be something else unless this is still not right:

    function setBGMPDefaultIconByCategory( $iconURL, $placemarkID )
    {
        $placemarkCategories = wp_get_object_terms( $placemarkID, 'bgmp-category' );
    
        foreach( $placemarkCategories as $pc )
            if( $pc->slug == 'shop' ) {
                $iconURL = 'https://www.gravatar.com/avatar/1cf0770522223715996d00a7fe911003?s=48&d=monsterid&r=g';
    		} else {
    			$iconURL = get_bloginfo( 'stylesheet_directory' ) . '/img/map_marker_generic.png';
    		}
        return $iconURL;
    }
    add_filter( 'bgmp_default-icon', 'setBGMPDefaultIcon', 10, 2);
    Thread Starter 3stripe

    (@3stripe)

    Have resorted to hacking the core.php file until I figure this out ??

    Plugin Author Ian Dunn

    (@iandunn)

    The bit in the readme works because there’s only a single line inside the foreach. When you add multiple lines, then you need to wrap them in braces; otherwise you can get unexpected results.

    You would need to do something like

    foreach( $placemarkCategories as $pc )
    {
    	if( $pc->slug == 'shop' )
    	{
    		$iconURL = 'https://www.gravatar.com/avatar/1cf0770522223715996d00a7fe911003?s=48&d=monsterid&r=g';
    	}
    	else
    	{
    		$iconURL = get_bloginfo( 'stylesheet_directory' ) . '/img/map_marker_generic.png';
    	}
    }

    I almost threw my laptop out of the window trying to fix this. Was looking through the code for hours.

    Bottom line, it was the bottom line:

    ‘setBGMPDefaultIcon’ should be ‘setBGMPDefaultIconByCategory’

    function setBGMPDefaultIconByCategory( $iconURL, $placemarkID )
    {
        $placemarkCategories = wp_get_object_terms( $placemarkID, 'bgmp-category' );
    
        foreach( $placemarkCategories as $pc )
            if( $pc->slug == 'shop' ) {
                $iconURL = 'https://www.gravatar.com/avatar/1cf0770522223715996d00a7fe911003?s=48&d=monsterid&r=g';
    		} else {
    			$iconURL = get_bloginfo( 'stylesheet_directory' ) . '/img/map_marker_generic.png';
    		}
        return $iconURL;
    }
    add_filter( 'bgmp_default-icon', 'setBGMPDefaultIconByCategory', 10, 2);

    -_-‘

    If you’re doing multiple lines. It’d be much more efficient to use switch instead of if statements. food for thought.

    switch($pc->slug) {
      case 'shop' : $iconURL; break;
      case 'store': $iconURL; break;
      default: $iconURL; break; 
    
    }

    Jesse.t
    can you give an example of the whole function using switch? I am a PHP novice. Thanks

    Sure.

    https://pastebin.com/QG9NvX1p

    replace slug in case ‘slug’: with the slug of your categories.. And change the iconURL to reflect your icons.

    Hello,

    Thank you for the great plugin! I tried to use a different picture for 3 categories, but unfortunately the places disappeared on the map.
    I used the belowing code and I added it with the “Add function” wordpress plugin.

    Plese be so kind and help me, what is the problem?

    Thank you very much,
    Andrea

    <?php
    function setBGMPDefaultIconByCategory( $iconURL, $placemarkID )
    {
        $placemarkCategories = wp_get_object_terms( $placemarkID, 'bgmp-category' );
    
        foreach( $placemarkCategories as $pc ) {
            switch($pc->slug) {
    		case 'headoffice' : $iconURL = get_bloginfo('https://web-reneszansz.hu/recept_blog/wp-content/themes/twentyeleven').'/images/headoffice-marker.png'; break;
    		case 'agents' : $iconURL = get_bloginfo('https://web-reneszansz.hu/recept_blog/wp-content/themes/twentyeleven').'/images/agents-marker.png'; break;
    		case 'portfolios' : $iconURL = get_bloginfo('https://web-reneszansz.hu/recept_blog/wp-content/themes/twentyeleven').'/images/portfolios-marker.png'; break;
    		default : $iconURL = get_bloginfo('https://web-reneszansz.hu/recept_blog/wp-content/themes/twentyeleven').'/images/portfolios-marker.png'; break;
    		}
    	}
        return $iconURL;
    }
    add_filter( 'bgmp_default-icon', 'setBGMPDefaultIconByCategory', 10, 2);
    ?>

    [Please post code between backticks or use the code button. Your posted code may now have been permanently damaged by the forum’s parser.]

    Plugin Author Ian Dunn

    (@iandunn)

    Hi Andrea,

    get_bloginfo('https://web-reneszansz.hu/recept_blog/wp-content/themes/twentyeleven').

    is probably part of the problem. Take a look at the WordPress Codex entry for get_bloginfo(). You want to be calling get_bloginfo( ‘wpurl’ ) instead.

    Better yet, use get_stylesheet_directory_uri() to get the URL of your theme.

    If that doesn’t fix it completely, I’d view the page source and look at what URLs are being generated for the marker, or use Firebug/Chrome Dev Tools to select the marker and look at the HTML to see.

    Hello Ian,
    Great, it works!!!
    Thank you very much for the prompt answer, I really appreciate it,
    BR
    Andi

    Hello Ian,
    One more question please, would it be possible to delete my full url of web-reneszansz.hu from the published code and use my question only as a example?
    Thank you very mutch,
    Andi

    and also this related message… ??

    Plugin Author Ian Dunn

    (@iandunn)

    Plugin authors don’t have the capability to edit other people’s posts. You’ll have to ask one of the forum moderators to do that, by adding the “modlook” tag to the thread.

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Custom category markers not working’ is closed to new replies.