Icons per status/custom fields/taxonomy

Home Forums Feature Requests Icons per status/custom fields/taxonomy

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #11869
    p36p
    Participant

    Hi,

    Is it possible to add automatically an icon per category or status (from availability calendar) or taxonomy ?

    Thanks a lot for your help

    p36p

    #11889
    Chris
    Keymaster

    Hi,

    There are two filters for this. ‘mappress_map_display’ is called just before the whole map is displayed, and ‘mappress_poi_iconid’ is called when preparing each poi for display.

    Here’s an example using the second filter. It sets posts with category ‘mycat1’ to iconid ‘blue-dot’, all other posts are unchanged.  The code could be added your function.php file:

    function myiconid($iconid, $poi) {
    if ($poi->postid && has_category('mycat1', $poi->postid))
    return 'blue-dot';
    else
    return $iconid;
    }
    add_action('mappress_poi_iconid', myiconid);
    
    #11896
    p36p
    Participant

    Thanks so much I’ll try this!

    #12019
    hithoo
    Participant

    Did you have any luck with this? I tried it and it did not work for me.

    #13622
    robbie59
    Participant

    Hello,

    How can I use this code to check the value of a taxonomy of a custom post type?

    function myiconid($iconid, $poi) {
    if ($poi->postid && has_category('mycat1', $poi->postid))
    return 'blue-dot';
    else
    return $iconid;
    }
    add_action('mappress_poi_iconid', myiconid);
    

    The blow is not working for me:

    function myiconid($iconid, $poi) {
    if ($poi->postid && has_term('459_res','crimes', $poi->postid))
    return 'assault.png';
    else
    return $iconid;
    }
    add_action('mappress_poi_iconid', myiconid);	
    	

    Thanks

    #13633
    Chris
    Keymaster

    Hi,

    The problem might be in the add_action() statement – I think if you don’t specify the number of arguments it default to only 1 (so you’d get only $iconid, not $poi). Try:

    add_action('mappress_poi_iconid', myiconid, 10, 2);

    #13634
    robbie59
    Participant

    Thanks, but I this code still did not work. .Any ideas? I really need this to work with terms

    
    function myiconid($iconid, $poi) {
    if ($poi->postid && has_term('459_veh','crimes', $poi->postid))
    return 'assault.png';
    else
    return $iconid;
    }
    	
    
    add_action('mappress_poi_iconid', myiconid, 10, 2);
    
    #13635
    Chris
    Keymaster

    There’s no way for me to know whether the has_term() call is working. You can try printing the output to see if the function is actually being called and whether the term is being found. Use echo or error_log(), something like:

    echo "postid: " . $poi->postid . "term: " . has_term('459_veh','crimes', $poi->postid);

    #13875
    Chris
    Keymaster

    Hi,

    I did some testing on the code and found there was a missing ‘p’ in the filter name. It’s corrected in 2.40.8 – email me if you need that upgrade, or you can use the filter as ‘mapress_poi_iconid’.

    Here’s another example that works for me (with 2.40.8):

    
    function myiconid($iconid, $poi) {
    	if ($poi->postid) {
    		if (has_category('catka', $poi->postid))
    			return 'blue-dot';
    		if (has_category ('catb', $poi->postid))
    			return 'purple-dot';
    	}
    	return $iconid;
    }
    
    add_filter('mappress_poi_iconid', 'myiconid', 10, 2);
    
    #14328
    andyunix
    Participant

    With the invaluable help of Chris, 🙂 🙂 we were able to find a solution to the problem, I’ll post the code:

    //Cutom Mappress

    function myiconid($iconid, $poi) {
    global $post;
    $postid = ($poi->postid) ? $poi->postid : $post->ID;
    if (has_term(30, 'ad_cat', $postid) && get_post_type($postid) == 'ad_listing')
    return 'icon.png';
    ;
    return $iconid;
    }
    add_filter('mappress_poi_iconid', 'myiconid', 10, 2);

    The parameters to be changed are: 30,(is id) ‘ad_cat'(is taxonomy) and ‘ad_listing'(is a post_type)

    Best Regards and thanks to all!!!

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