I have created a function that takes one parameter - post type, and will output each posts with some html and title, content etc within that. However, I want to be able to use functions associated with $post, especially the_excerpt. However, when I try to use my function in my sidebar php widget, it simply outputs the main page's title and content, not the custom queries post info.

If I run the function in the page, it works fine though, and echos out the custom queries' post details. You may ask why I don't just put this in the sidebar, well it's too messy and I'll be reusing it with different custom posts, so I thought I'd write a function.