WP: Get Post Permalink
I came across two functions that will get a posts permalink. One of them causes some warnings to show when error display is on. The warnings are not critical as the function is a get function, it is not attempting to update the database. However I decided to try the other function and that also returns a posts permalink but without the errors. So if you want to get the permalink without any other fancy abilities in a function just use the first one below…
get_permalink($post_id)
This will return the permalink and it requires the post ID unless you are using it inside of the loop, then using get_permalink() without passing parameters is fine. Below is a sample of how I was using it within a table.
<?php $link = '<td><br /><a href="'.get_permalink($r->ecipostid).'" class="button-primary">View Post</a><br /></td>'; ?>
get_post_permalink()
This is the function that caused the warnings. It has 3 optional parameters that I will not go into, instead refer to the WordPress.org get_post_permalink page.
Example Permalink
On my computer while testing a permalink to a post, returned from get_permalink() will look like…
http://localhost/wordpress-testing/eci/?p=1012
Online this permalink would be…
http://www.webtechglobal.co.uk/?p=1012