Map Icon

This topic contains 11 replies, has 3 voices, and was last updated by  Stiofan O’Connor 7 years, 1 month ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket

Tagged: , ,

  • Author
    Posts
  • #369462

    Neil Hall
    Buyer
    Post count: 83

    Hi

    We have set up map icons for main categories and sub-categories. When listings are posted from the front end a sub-category is selected which automatically selects the main category (which is what we want).

    The problem that we are seeing is that when the listings are displayed on a map that it automatically displays the icon from the main category. Is there a function where we can force the display of the sub-category icon?

    #369467

    Kor
    Moderator
    Post count: 16516

    Hi Neil,

    While you add the category to the listing, did you mark the sub-category as the “Default” as shown in this screenshot ? http://prntscr.com/ents12

    Thanks!

    #369480

    Neil Hall
    Buyer
    Post count: 83

    Hi Kor

    Sorry, I should have explained. We are using the ‘checkbox’ for the category selection. I think the screenshot is if you use the ‘Ajax chained’ category selection (which we do not want to use).

    Is there any way to set the ‘Sub-Cat’ as the default when using checkbox?

    Best Regards
    Neil

    #369589

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    Hi Neil,

    There is no way to to it with the tick filters, in that case i think it just assigns the lowest id or the first id.

    If you only have a few cats you would filter the listing array before its output to change the default cat on the fly using the ‘geodir_before_marker_post_process’ hook.

    Stiofan

    #370220

    Neil Hall
    Buyer
    Post count: 83

    Hi Stiofan

    We have over 20 cpt’s all with a varying amount of sub-categories, so it may be difficult.

    However, th way that we have set them all up means that the sub-category id is always higher than the main-category id.

    Is there any way that we could change the code somewhere so it took the highest id instead of taking the lowest id?

    Best Regards
    Neil

    #370358

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    Hi Neil,

    This might work in that case?

    
    
    add_filter('geodir_before_marker_post_process','_my_use_higher_cat_id');
    
    function _my_use_higher_cat_id($posts){
    
    	if(!empty($posts)){
    		foreach($posts as $key=>$post){
    			$pt = esc_attr($_REQUEST['gd_posttype']);
    			if(isset($post->{$pt.'category'})){
    				$cats = array_filter(explode(',',$post->{$pt.'category'}));
    				$post->default_category = max($cats);
    				$posts[$key] = $post;
    			}
    
    		}
    	}
    	return $posts;
    }

    Stiofan

    #370469

    Neil Hall
    Buyer
    Post count: 83

    Hi Stiofan

    Thank you for the code. I have run a few tests.

    If I set the GD>Design>Listings> New listing default status to ‘Publish’ then it works really great and the correct icon is published on the Map.

    However, if the above setting is set to ‘Draft’ (which is how we would ideally like it) and the Listing is manually published in the backend then it reverts back to the main-cat icon.

    I did find a way around this in the backend by deleting the categories and just clicking on a sub-cat before clicking on the publish button which then gives the correct result. But if you have another solution that would work when the post is published in the backend it would really help.

    Best Regards
    Neil

    #370613

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    I made a tiny change to my code can u re-try it please.

    Stiofan

    #370633

    Neil Hall
    Buyer
    Post count: 83

    Hi Stiofan

    That seems to work in the same way. So if the Listing is automatically published then it has the correct icon.

    However, as soon as I go to the listing in the backend and then update it (without changing anything) then it selects the icon from the main category.

    Again, if I deselect all the categories in the backend and just select the sub-category before I press the update button, then it uses the correct ‘sub-category’ icon.

    Best Regards
    Neil

    #370664

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    what map are u testing on, the home map? Are u sure your sub cat has a higher id than the main cat?

    Stiofan

    #370677

    Neil Hall
    Buyer
    Post count: 83

    Hi Stiofan

    I am testing in the listing-detail page within the Map tab.

    In the tests that I am running, which are with the place cpt the main category ‘Places to Visit’ has ID 15. Sub-categories that I have tested have id’s of 262, 267, 712 etc.

    As I said, the code does work in the front end when posting listings. The only problem seems to be when the listing is either approved or updated in the backend.

    Let me know if you need any further info.

    Best Regards
    Neil

    #370797

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    OK we were thinking of different maps.

    You would need to filter the array, its not a very easy thing
    this is the filter you would use, but it wont change the icon, you would need to do that

    
    
    add_filter('geodir_map_canvas_jason_detail_page_map_canvas','_my_edit_detail_marker',10,1);
    
    function _my_edit_detail_marker($map_canvas_jason_args){
    
    	echo '###';
    	print_r($map_canvas_jason_args);
    
    	return $map_canvas_jason_args;
    }

    Stiofan

Viewing 12 posts - 1 through 12 (of 12 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket