Map Icon
This topic contains 11 replies, has 3 voices, and was last updated by Stiofan O’Connor 7 years, 7 months ago.
We have moved to a support ticketing system and our forums are now closed.
Open Support TicketTagged: icon, map, sub-category
-
AuthorPosts
-
March 24, 2017 at 8:09 am #369462
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?
March 24, 2017 at 8:28 am #369467Hi 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!
March 24, 2017 at 9:32 am #369480Hi 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
NeilMarch 24, 2017 at 3:01 pm #369589Hi 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
March 27, 2017 at 6:37 pm #370220Hi 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
NeilMarch 28, 2017 at 12:12 pm #370358Hi 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
March 28, 2017 at 6:57 pm #370469Hi 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
NeilMarch 29, 2017 at 2:19 pm #370613I made a tiny change to my code can u re-try it please.
Stiofan
March 29, 2017 at 3:41 pm #370633Hi 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
NeilMarch 29, 2017 at 5:57 pm #370664what map are u testing on, the home map? Are u sure your sub cat has a higher id than the main cat?
Stiofan
March 29, 2017 at 7:02 pm #370677Hi 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
NeilMarch 30, 2017 at 10:27 am #370797OK 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 thatadd_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
-
AuthorPosts
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket