While the previous recipe may be very useful to get access to post data outside the loop, there's still something very important that the get_post()
function can't do—retrieving a permalink. Sure, it can retrieve the guid
(the classic URL which looks like http://www.yourblog.com/?p=15) but it cannot retrieve the permalink. In this recipe, I'm going to show you how it is possible.
As for the get_post()
function, we're going to use the get_permalink()
function that will execute one more SQL query on your WordPress database. Therefore, use it—only when you have no other choice—to reduce page loading time.