We have seen few get_posts() function examples before. We can use same function with few arguments to get the list from custom post types.
-1,
'post_type' => 'custom_post_type'
));
if( $posts ): ?>
Why to use setup_postdata() and wp_reset_postdata()?
setup_postdata() sets up the global post data. It helps in formatting custom query results when we use custom query with Template tags.
wp_reset_postdata() function restores the global $post variable to the current post in the main query. That’s why we use it after looping through a separate query.
custom functions get_posts list post type