Conditional Tabs

This topic contains 3 replies, has 2 voices, and was last updated by  Paul Ist 5 years, 9 months ago.

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

Open Support Ticket
  • Author
    Posts
  • #486765

    Paul Ist
    Free User
    Post count: 2

    Hi!
    How can I set a condition for a custom tab (eg: “More Details”) to show up only on places that belong to a certain category (eg: “Kindergartens”).
    WP 5.2/ GeoDirectory 2.0.0.58

    ps: I found some examples for V1 but they seem to not work for V2.

    add_filter(‘geodir_detail_page_tab_list_extend’) and then unset($tab_array[‘your_tab’]). Are these filters/hooks still available? If not, what’s their equivalent in V2?

    #486851

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    Hi Paul,

    The below example would remove the tab “more_details” for all posts that are not in the cat with ID = 100.

    Its best to use the tab key rather than the name (the tab key is what appears after the # when u click the tab).

    add_filter('geodir_tab_settings','_my_tabs_edit',10,2);
    function _my_tabs_edit($tabs,$post_type){
      global $gd_post;
      
      if(!empty($tabs) && !empty($gd_post->post_category)){
    	$cats = array_filter(explode(",",$gd_post->post_category));
    	$cat_id = 100; // set id here
    	$remove_tab_key = "more_details"; // set tab key here
    	if( !in_array($cat_id,$cats) ){
    	  foreach($tabs as $key => $tab){
    	  	if($tab->tab_key==$remove_tab_key){
    		 unset($tabs[$key]);// remove the tab
    		}
    	  }
    	}
    	
      }
    
      return $tabs;
    }

    Hope this helps.

    Thanks,

    Stiofan

    #488817

    Paul Ist
    Free User
    Post count: 2

    Thanks a lot Stiofan!
    Works perfectly!

    #488818

    Paul Ist
    Free User
    Post count: 2

    Thanks!
    I will probably try your solution in another context.
    For now Stiofan’s solution works for me.

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

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

Open Support Ticket
20% Discount Offer
Hurry! Get your 20% discount before it expires. Get 20% Discount