I have a website that is a custom PHP site hosted at http://mysite.com. Then I have a Wordpress instance running on sub-domain at http://blog.mysite.com, where some post can be at URL http://blog.mysite.com/this-is-my-test-post-entry
In landing page of mysite.com I connect to Wordpress DB and fetch out last 5 entries from wp_posts table and show them on my home page. The problem is I don't know how to get the right links to those posts? Wordpress generates permalinks() but I don't know how to get them?
I thought Wordpress takes post title string and replaces spaces with "-" and uses that string for post URL. But doesn't work for all posts...
Any suggestions?
This may not be exactly what you are looking for, but it will work...
When you fetch your last 5 posts, get the id (make sure you're filtering on your post_type field to avoid grabbing things like revisions, attachments, etc).
You can simply build your URL like http://blog.mysite.com/?p=ID (where ID is the ID from the database). WordPress will automatically redirect the user to the proper page with the custom permalink that you defined in your settings.
Let me know if you need a hand with the PHP.