Hi guys, a really quick one for you today. I found the need to grab the permalink for the first post in a variety of custom post types. I used the following code, outside of the loop:
<?php $post = get_posts('numberposts=1&post_type=my-post-type' ); ?> <a href="<?php echo get_permalink( $post[0]->ID ); ?>"><?php echo $post[0]->post_title; ?></a>
The above will grab the first post as an object array, and allow you to access information about it. You can use the offset parameter to get the 2nd, 3rd, 4th post, and so on.
Anyway, that’s about it!
Resources
get_post()
get_permalink()