Wordpress get_permalink bug - does not return clean URLs in admin area?

1.5k views Asked by At

I have set all my site urls to the custom structure in Permalink Settings:

/portfolio/%postname%/

But when I try to get a post clean URL in my admin area at http://mywebsite.com/wp-admin/post.php?post=415&action=edit:

// Get post/page ID.
$post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ;

get_permalink($post->ID);

Result:

http://mywebsite.com/?p=415

But it should be:

http://mywebsite.com/portfolio/sample-1/

Why? What have I missed?

1

There are 1 answers

0
Run On

The cause of it is that the page has no slug data. Only the slug data is stored then I can get the clean URL.