Custom Tabs on Detail Site only at specific Custom Post Type

This topic contains 7 replies, has 3 voices, and was last updated by  thomaskhom 9 years, 8 months ago.

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

Open Support Ticket
  • Author
    Posts
  • #10620

    thomaskhom
    Buyer
    Post count: 11

    Hi @ all

    i added custom tabs on the detail Site Code is below. My question how i need to modify the code to show the tabs only at detail Site from an specific custom post type. Example the Customs Tabs should by shown only at hotel listings detail pages.

    
    
    add_filter('geodir_detail_page_tab_list_extend', 'geodir_detail_page_tab_list_extend') ;
    
    function geodir_detail_page_tab_list_extend($tab_array)
    {
     $tab_array['sportaktiv_tab'] = array( 
    										'heading_text' =>  __('SPORTaktiv',GEODIRECTORY_TEXTDOMAIN),
    										'is_active_tab' => false,
    										'is_display' =>  apply_filters('geodir_detail_page_tab_is_display', true, 'sportaktiv_tab'),
    										'tab_content' => ''
    									);
        
         	$tab_array['routen_tab'] = array( 
    										'heading_text' =>  __('Routen',GEODIRECTORY_TEXTDOMAIN),
    										'is_active_tab' => false,
    										'is_display' =>  apply_filters('geodir_detail_page_tab_is_display', true, 'routen_tab'),
    										'tab_content' => ''
    									);
    
         	$tab_array['sportdetails_tab'] = array( 
    										'heading_text' =>  __('Sportdetails',GEODIRECTORY_TEXTDOMAIN),
    										'is_active_tab' => false,
    										'is_display' =>  apply_filters('geodir_detail_page_tab_is_display', true, 'sportdetails_tab'),
    										'tab_content' => ''
    									);
    
    	return $tab_array ;
    }
    
    add_action('geodir_after_tab_content' ,'geodir_my_new_tab_content');
    function geodir_my_new_tab_content($tab_index)
    {
    	if($tab_index =='sportaktiv_tab')
    	{
            global $wpdb;
            $id = get_the_ID();
            $sportaktivinfos = $wpdb->get_var("SELECT geodir_c4y_sportaktiv_infos FROM geodir_gd_aktiv_hotels_detail WHERE post_id = $id ");
         
       echo $sportaktivinfos;
            
    	}
    
        
        if($tab_index =='routen_tab')
    	{
            global $wpdb;
            $id = get_the_ID();
            $routeninfos = $wpdb->get_var("SELECT geodir_c4y_detail_nearby_routes FROM geodir_gd_aktiv_hotels_detail WHERE post_id = $id ");
    
       echo $routeninfos;
    	}
    	
    	
    if($tab_index =='sportdetails_tab')
    	{
            global $wpdb;
            $id = get_the_ID();
            $bikeinfos = $wpdb->get_var("SELECT geodir_c4y_detail_sport FROM geodir_gd_aktiv_hotels_detail WHERE post_id = $id ");
    
       echo $bikeinfos;
    	}	
    }

    Thanks for help .
    Thomas

    P.S: and sorry for my bad english 😉 not my native language.

    #10622

    Simone
    Expired Member
    Post count: 3515

    Hello Thomas,
    try the following code (not tested on my site)

    
    
    add_filter('geodir_detail_page_tab_list_extend', 'geodir_detail_page_tab_list_extend') ;
    
    function geodir_detail_page_tab_list_extend($tab_array)
    {
     $tab_array['sportaktiv_tab'] = array( 
    										'heading_text' =>  __('SPORTaktiv',GEODIRECTORY_TEXTDOMAIN),
    										'is_active_tab' => false,
    										'is_display' =>  apply_filters('geodir_detail_page_tab_is_display', true, 'sportaktiv_tab'),
    										'tab_content' => ''
    									);
        
         	$tab_array['routen_tab'] = array( 
    										'heading_text' =>  __('Routen',GEODIRECTORY_TEXTDOMAIN),
    										'is_active_tab' => false,
    										'is_display' =>  apply_filters('geodir_detail_page_tab_is_display', true, 'routen_tab'),
    										'tab_content' => ''
    									);
    
         	$tab_array['sportdetails_tab'] = array( 
    										'heading_text' =>  __('Sportdetails',GEODIRECTORY_TEXTDOMAIN),
    										'is_active_tab' => false,
    										'is_display' =>  apply_filters('geodir_detail_page_tab_is_display', true, 'sportdetails_tab'),
    										'tab_content' => ''
    									);
    
    	return $tab_array ;
    }
    
    add_action('geodir_after_tab_content' ,'geodir_my_new_tab_content');
    function geodir_my_new_tab_content($tab_index)
    {
    global $post; 
    
    $current_posttype = geodir_get_current_posttype();
    
    	if($current_posttype != "YOUR CUSTOM TYPE eg gd_place") { 
    
    	if($tab_index =='sportaktiv_tab')
    	{
            global $wpdb;
            $id = get_the_ID();
            $sportaktivinfos = $wpdb->get_var("SELECT geodir_c4y_sportaktiv_infos FROM geodir_gd_aktiv_hotels_detail WHERE post_id = $id ");
         
       echo $sportaktivinfos;
            
    	}
    
        
        if($tab_index =='routen_tab')
    	{
            global $wpdb;
            $id = get_the_ID();
            $routeninfos = $wpdb->get_var("SELECT geodir_c4y_detail_nearby_routes FROM geodir_gd_aktiv_hotels_detail WHERE post_id = $id ");
    
       echo $routeninfos;
    	}
    	
    	
    if($tab_index =='sportdetails_tab')
    	{
            global $wpdb;
            $id = get_the_ID();
            $bikeinfos = $wpdb->get_var("SELECT geodir_c4y_detail_sport FROM geodir_gd_aktiv_hotels_detail WHERE post_id = $id ");
    
       echo $bikeinfos;
    	}	
    }
    }

    what I’ve done is to add an if statement so you need to add your post type in the row where it says:
    if($current_posttype != “YOUR CUSTOM TYPE eg gd_place”) {

    Don’t worry about your english, it is surely better than mine 😉

    #10628

    thomaskhom
    Buyer
    Post count: 11

    Hello Simone,

    thanks for the quick answer but the code dont work for me.

    I get always the Tabs and they are always empty.

    #10629

    Simone
    Expired Member
    Post count: 3515

    could you please give me your FTP in a private reply? thanks

    #10630

    thomaskhom
    Buyer
    Post count: 11
    This reply has been marked as private.
    #10631

    Vikas
    Full Member
    Post count: 1128

    @Simone sorry to bother but he wants to remove the tab not the content, so here is better code

    
    
    
    add_filter('geodir_detail_page_tab_list_extend', 'geodir_detail_page_tab_list_extend') ;
    
    function geodir_detail_page_tab_list_extend($tab_array)
    {
    global $post ;
    if($post->post_type != 'Write the post type u want to hide this tab for') // e.g gd_place
    {
     $tab_array['sportaktiv_tab'] = array( 
    										'heading_text' =>  __('SPORTaktiv',GEODIRECTORY_TEXTDOMAIN),
    										'is_active_tab' => false,
    										'is_display' =>  apply_filters('geodir_detail_page_tab_is_display', true, 'sportaktiv_tab'),
    										'tab_content' => ''
    									);
        
         	$tab_array['routen_tab'] = array( 
    										'heading_text' =>  __('Routen',GEODIRECTORY_TEXTDOMAIN),
    										'is_active_tab' => false,
    										'is_display' =>  apply_filters('geodir_detail_page_tab_is_display', true, 'routen_tab'),
    										'tab_content' => ''
    									);
    
         	$tab_array['sportdetails_tab'] = array( 
    										'heading_text' =>  __('Sportdetails',GEODIRECTORY_TEXTDOMAIN),
    										'is_active_tab' => false,
    										'is_display' =>  apply_filters('geodir_detail_page_tab_is_display', true, 'sportdetails_tab'),
    										'tab_content' => ''
    									);
    }// end of if for post type check 
    
    	return $tab_array ;
    }
    

    Let me know if it works.

    Thanks

    #10633

    Simone
    Expired Member
    Post count: 3515

    oops..ive placed the if statement in the wrong functions, it was supposed to stay in the previous “geodir_detail_page_tab_list_extend”.

    edit- wow Vikas just wrote that 🙂

    #10634

    thomaskhom
    Buyer
    Post count: 11

    Hello,

    thanks to both code from Vikas works perfect.

    greets Thomas

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

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

Open Support Ticket