Can I find out what is wrong with this code?

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

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

Open Support Ticket

Tagged: , ,

  • Author
    Posts
  • #338609

    Tom Rendle
    Buyer
    Post count: 46

    I am trying to reorder tabs, specifically getting rid of reviews section for gd_completed_system and gd_project_proposal.

    // This is the add filter action which will use the function below to re-order tabs.
    add_filter(‘geodir_detail_page_tab_list_extend’, ‘geodir_detail_page_tab_list_extend’) ;

    //This is the actual function to re-order tabs
    function geodir_detail_page_tab_list_extend($tab_array)
    {

    // before creating the new array which will re-order the tabs, we check if the custom post type is “Places”

    if ( ‘gd_project_proposal’ == get_post_type() ) {

    // here you can modify the array and re-arrange tabs as you wish, you can create a completely new array too.

    // this is the post profile tab, by default is the 1st
    if(isset($tab_array[‘post_profile’])){
    $new_tab_array[‘post_profile’] = $tab_array[‘post_profile’]; // set in new array
    // IMPORTANT the following code tells GeoDirectory that this is no longer the default active tab
    $new_tab_array[‘post_profile’][‘is_active_tab’]=”;
    unset($tab_array[‘post_profile’]);//unset in old one
    }

    // this is the post info tab (optional for custom fields), by default, if available, is the 2nd.
    if(isset($tab_array[‘post_info’])){
    $new_tab_array[‘post_info’] = $tab_array[‘post_info’];// set in new array
    unset($tab_array[‘post_info’]);//unset in old one
    }
    // this is the images tab, by default is the 3rd
    if(isset($tab_array[‘post_images’])){
    $new_tab_array[‘post_images’] = $tab_array[‘post_images’];// set in new array
    unset($tab_array[‘post_images’]);//unset in old one
    }

    // this is the video tab, appears only if there are videos and by default is the 4th
    if(isset($tab_array[‘post_video’])){
    $new_tab_array[‘post_video’] = $tab_array[‘post_video’];// set in new array
    unset($tab_array[‘post_video’]);//unset in old one
    }

    // this is the speacial offer tab, appears only if there are special offers and by default is the 5th
    if(isset($tab_array[‘special_offers’])){
    $new_tab_array[‘special_offers’] = $tab_array[‘special_offers’];// set in new array
    unset($tab_array[‘special_offers’]);//unset in old one
    }

    // this is the map tab, by default is the 6th
    if(isset($tab_array[‘post_map’])){
    $new_tab_array[‘post_map’] = $tab_array[‘post_map’];// set in new array
    unset($tab_array[‘post_map’]);//unset in old one
    }

    // this is the related listing tab, it is optional and by default is the 8th
    if(isset($tab_array[‘related_listing’])){
    $new_tab_array[‘related_listing’] = $tab_array[‘related_listing’];// set in new array
    unset($tab_array[‘related_listing’]);//unset in old one
    }

    // check if the custom post type is “Events”
    elseif ( ‘gd_completed_system’ == get_post_type() ) {

    // this is the post info tab (optional for custom fields), by default, if available, is the 2nd.
    if(isset($tab_array[‘post_info’])){
    $new_tab_array[‘post_info’] = $tab_array[‘post_info’];// set in new array
    unset($tab_array[‘post_info’]);//unset in old one
    }
    // this is the images tab, by default is the 3rd
    if(isset($tab_array[‘post_images’])){
    $new_tab_array[‘post_images’] = $tab_array[‘post_images’];// set in new array
    unset($tab_array[‘post_images’]);//unset in old one
    }

    // this is the video tab, appears only if there are videos and by default is the 4th
    if(isset($tab_array[‘post_video’])){
    $new_tab_array[‘post_video’] = $tab_array[‘post_video’];// set in new array
    unset($tab_array[‘post_video’]);//unset in old one
    }
    // this is the post profile tab, by default is the 1st
    if(isset($tab_array[‘post_profile’])){
    $new_tab_array[‘post_profile’] = $tab_array[‘post_profile’]; // set in new array
    // IMPORTANT the following code tells GeoDirectory that this is no longer the default active tab
    $new_tab_array[‘post_profile’][‘is_active_tab’]=”;
    unset($tab_array[‘post_profile’]);//unset in old one
    }

    // this is the speacial offer tab, appears only if there are special offers and by default is the 5th
    if(isset($tab_array[‘special_offers’])){
    $new_tab_array[‘special_offers’] = $tab_array[‘special_offers’];// set in new array
    unset($tab_array[‘special_offers’]);//unset in old one
    }

    // this is the map tab, by default is the 6th
    if(isset($tab_array[‘post_map’])){
    $new_tab_array[‘post_map’] = $tab_array[‘post_map’];// set in new array
    unset($tab_array[‘post_map’]);//unset in old one
    }

    // this is the related listing tab, it is optional and by default is the 8th
    if(isset($tab_array[‘related_listing’])){
    $new_tab_array[‘related_listing’] = $tab_array[‘related_listing’];// set in new array
    unset($tab_array[‘related_listing’]);//unset in old one
    }

    } // If Check for Events ends here

    return $new_tab_array ; } // If Check for Places ends here
    // Here we tell GeoDirectory to use the regular array for all other custom post types.
    else { return $tab_array ; }

    }

    #338613

    Jeff
    Buyer
    Post count: 188

    New code is below. The short version is that you got your conditions mixed up. Your if’s were embedded where they didn’t need to be and you weren’t returning properly. This version should be better.

    Also, the unset lines for the $tab_array aren’t needed since you don’t use it and don’t return it. Micro-optimization, but cleans up the code.

    
    
    
    // This is the add filter action which will use the function below to re-order tabs.
    add_filter( 'geodir_detail_page_tab_list_extend', 'geodir_detail_page_tab_list_extend' );
    
    //This is the actual function to re-order tabs
    function geodir_detail_page_tab_list_extend( $tab_array ) {
    	// Start with a clean $new_tab_array
    	$new_tab_array = [];
    
    	// before creating the new array which will re-order the tabs, we check if the custom post type is “Project Proposal”
    	if ( 'gd_project_proposal' == get_post_type() ) {
    
    	// here you can modify the array and re-arrange tabs as you wish, you can create a completely new array too.
    
    		// this is the post profile tab, by default is the 1st
    		if ( isset( $tab_array['post_profile'] ) ) {
    			$new_tab_array['post_profile'] = $tab_array['post_profile']; // set in new array
    			// IMPORTANT the following code tells GeoDirectory that this is no longer the default active tab
    			$new_tab_array['post_profile']['is_active_tab'] = '';
    			unset( $tab_array['post_profile'] );//unset in old one
    		}
    
    		// this is the post info tab (optional for custom fields), by default, if available, is the 2nd.
    		if ( isset( $tab_array['post_info'] ) ) {
    			$new_tab_array['post_info'] = $tab_array['post_info'];// set in new array
    			unset( $tab_array['post_info'] );//unset in old one
    		}
    		// this is the images tab, by default is the 3rd
    		if ( isset( $tab_array['post_images'] ) ) {
    			$new_tab_array['post_images'] = $tab_array['post_images'];// set in new array
    			unset( $tab_array['post_images'] );//unset in old one
    		}
    
    		// this is the video tab, appears only if there are videos and by default is the 4th
    		if ( isset( $tab_array['post_video'] ) ) {
    			$new_tab_array['post_video'] = $tab_array['post_video'];// set in new array
    			unset( $tab_array['post_video'] );//unset in old one
    		}
    
    		// this is the speacial offer tab, appears only if there are special offers and by default is the 5th
    		if ( isset( $tab_array['special_offers'] ) ) {
    			$new_tab_array['special_offers'] = $tab_array['special_offers'];// set in new array
    			unset( $tab_array['special_offers'] );//unset in old one
    		}
    
    		// this is the map tab, by default is the 6th
    		if ( isset( $tab_array['post_map'] ) ) {
    			$new_tab_array['post_map'] = $tab_array['post_map'];// set in new array
    			unset( $tab_array['post_map'] );//unset in old one
    		}
    
    		// this is the related listing tab, it is optional and by default is the 8th
    		if ( isset( $tab_array['related_listing'] ) ) {
    			$new_tab_array['related_listing'] = $tab_array['related_listing'];// set in new array
    			unset( $tab_array['related_listing'] );//unset in old one
    		}
    
    		// ** Return the $new_tab_array inside Project Proposal
    		return $new_tab_array;
    
    	} elseif ( 'gd_completed_system' == get_post_type() ) {
    
    		// this is the post info tab (optional for custom fields), by default, if available, is the 2nd.
    		if ( isset( $tab_array['post_info'] ) ) {
    			$new_tab_array['post_info'] = $tab_array['post_info'];// set in new array
    			unset( $tab_array['post_info'] );//unset in old one
    		}
    
    		// this is the images tab, by default is the 3rd
    		if ( isset( $tab_array['post_images'] ) ) {
    			$new_tab_array['post_images'] = $tab_array['post_images'];// set in new array
    			unset( $tab_array['post_images'] );//unset in old one
    		}
    
    		// this is the video tab, appears only if there are videos and by default is the 4th
    		if ( isset( $tab_array['post_video'] ) ) {
    			$new_tab_array['post_video'] = $tab_array['post_video'];// set in new array
    			unset( $tab_array['post_video'] );//unset in old one
    		}
    
    		// this is the post profile tab, by default is the 1st
    		if ( isset( $tab_array['post_profile'] ) ) {
    			$new_tab_array['post_profile'] = $tab_array['post_profile']; // set in new array
    			// IMPORTANT the following code tells GeoDirectory that this is no longer the default active tab
    			$new_tab_array['post_profile']['is_active_tab'] = '';
    			unset( $tab_array['post_profile'] );//unset in old one
    		}
    
    		// this is the speacial offer tab, appears only if there are special offers and by default is the 5th
    		if ( isset( $tab_array['special_offers'] ) ) {
    			$new_tab_array['special_offers'] = $tab_array['special_offers'];// set in new array
    			unset( $tab_array['special_offers'] );//unset in old one
    		}
    
    		// this is the map tab, by default is the 6th
    		if ( isset( $tab_array['post_map'] ) ) {
    			$new_tab_array['post_map'] = $tab_array['post_map'];// set in new array
    			unset( $tab_array['post_map'] );//unset in old one
    		}
    
    		// this is the related listing tab, it is optional and by default is the 8th
    		if ( isset( $tab_array['related_listing'] ) ) {
    			$new_tab_array['related_listing'] = $tab_array['related_listing'];// set in new array
    			unset( $tab_array['related_listing'] );//unset in old one
    		}
    
    		// ** Return the $new_tab_array inside Completed System
    		return $new_tab_array;
    
    		// If Check for Completed System ends here
    	} else {
    		// Here we tell GeoDirectory to use the regular array for all other custom post types.
    		return $tab_array;
    	}
    
    }
    
    #338620

    Tom Rendle
    Buyer
    Post count: 46

    Thank you so much. Works perfectly.

    #339444

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    Thanks Jeff 🙂

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