Inconsistent results with custom icons

Home Forums MapPress Support Inconsistent results with custom icons

Tagged: 

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #14352
    beaver
    Participant

    Hi Chris

    I’m using the following code to show custom icons.

    function myiconid($iconid, $poi) {
      global $post;
      $postid = ($poi->postid) ? $poi->postid : $post->ID;
    
     if ( has_term( 'apples', 'product_cat' )) {
        return 'apples.png';
    	}
    		
     else if ( has_term( 'pears', 'product_cat' )) { 
        return 'pears.png';
    	}
    
    else {
      return $iconid;
    }
    
    }
    add_filter('mappress_poi_iconid', 'myiconid', 10, 2);
    

    This works ok when the map is being loaded in a category archive where all the locations belong to the same category. Then the custom icon is shown.

    But when I do a mashup like this I don’t get any of the custom icons showing. It just defaults to the standard icon.

    function big_map() {
    
    is_page( 303 ); {
    echo do_shortcode('[mashup query="post_type=product" width="100%" height="350px"]');
     }
       }
    add_action( 'genesis_entry_content', 'big_map' );
    
    #14353
    Chris
    Keymaster

    Hi,

    Each POI has a different post ID. It looks like you’re setting a variable for that ID but not including it in the has_term() call.

    If the ID is missing WordPress used the current post instead (and in archives, that’s probably empty).

    Try instead:

    if ( has_term( 'apples', 'product_cat', $postid )) {
        return 'apples.png';
    }
    
     else if ( has_term( 'pears', 'product_cat', $postid )) { 
        return 'pears.png';
    	}
    
    #14355
    beaver
    Participant

    Thanks Chris! That fixed the problem.

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