I'm automatically generating links to (supposed) pages/posts.
These links are generated by get_permalink( $post->ID ), so in_theory, should be valid links. Unfortunately, in some situations, where the $post is actually a nav menu item, there is a "theoretical" permalink that actually doesn't correspond to an actual page.
So, sometimes, the page the link points to doesn't actually exist. I would like to be able to detect this condition (ie: broken link) prior to outputting the HTML for that link, perhaps substituting it for something else.
I don't want to open a separate HTTP request or socket to do this because that would slow down page load times while waiting for the response. I'd like to leverage WordPress' built-in rewrite logic to determine what the link would be and whether that corresponds to any page/post record in the DB. WordPress does this automatically already when it pulls up the correct page, so in theory this should be possible.
My question really is: are there any functions or methods of WP_Rewrite that already facilitate this, or do I need to roll my own code?