如何在函数中添加WordPress循环?

I want to add WordPress loop in function. I tried adding this code in function but it's not working. Using global $post; also not take any effect. Can anyone please tell me how to add loop in function?

Loop:

$term_lists = wp_get_post_terms($post->ID, 'vendors', array("fields" => "all"));

foreach($term_lists as $term_singles) {

echo $custotaxos = $term_singles->slug."<br>"; //do something here

$myposts = get_posts(array(
    'showposts' => -1,
    'post_type' => 'vendor',
    'tax_query' => array(
        array(
        'taxonomy' => 'vendors',
        'field' => 'slug',
        'terms' => array($term_singles->name))
    ))
);

foreach ($myposts as $mypost) {
      echo $mypost->post_title . '<br/>';
      echo  $mypost->ID . '<br/>';
echo get_permalink($mypost->ID);

echo "<br>";
}

}

Function:

function woo_custom_product_tab_content() {

}
add_filter( 'woocommerce_product_tabs', 'woo_custom_product_tab' );