Site icon Hip-Hop Website Design and Development

switch_to_blog( ) content disappears after load

I’m working on building a custom extension to BuddyBoss that adds a tab to the user’s profile to view that particular user’s wishlist. When the page initially loads the correct data is being pulled in by the code but after 1-2 seconds the content that was pulled in from the shortcode disappears and shows no tractors in the user’s wishlist. Is there a way to get this to stop?

I am using a multi-site wordpress setup and the Favorites list is generated by site id 1, then the social profile is on site id 2. The code below grabs the BuddyBoss profile ID of the profile you are viewing, then dynamically adds the users id into the favorites shortcode. Then the shortcode displays the favorited items of that user.

add_action( 'bp_setup_nav', 'zaks_buddypress_tab_3', 1000 );

function wishlists () {
    add_action( 'bp_template_title', 'zaks_buddypress_wishlists_title' );
    add_action( 'bp_template_content', 'zaks_buddypress_wishlists_content' );
    bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
}


function zaks_buddypress_wishlists_title() {
  _e( 'Favorite Tractors', 'dietzendev' );
}

function zaks_buddypress_wishlists_content() {

$userNameID = bp_displayed_user_id();

switch_to_blog( 1 ); 

$output = do_shortcode('[user_favorites user_id="' . $userNameID . '" include_links="true" site_id="1", include_thumbnails="true" thumbnail_size="medium" include_excerpt="false"]');

restore_current_blog();
 
echo $output;
}
?>

When the page initially loads the shortcode works and pulls in the correct data, but then it seems to break once the page load finishes. Any ideas on what I can do?!

I HAVE THIS FIXED!

It was pulling in the JS for the wishlists twice which was causing it to error. Once I removed that it all worked!