Title: Permalink
Last modified: July 4, 2022

---

# Permalink

 *  [WebmasterNYC01](https://wordpress.org/support/users/webmasternyc01/)
 * (@webmasternyc01)
 * [3 years, 11 months ago](https://wordpress.org/support/topic/permalink-123/)
 * `why is not returning the full permalink with page name.
 * get_post_permalink( $id, $leavename = true, $sample = false );

Viewing 12 replies - 1 through 12 (of 12 total)

 *  Moderator [threadi](https://wordpress.org/support/users/threadi/)
 * (@threadi)
 * [3 years, 11 months ago](https://wordpress.org/support/topic/permalink-123/#post-15796246)
 * Here you write the function call from [https://developer.wordpress.org/reference/functions/get_post_permalink/](https://developer.wordpress.org/reference/functions/get_post_permalink/)–
   how did _you _call it to get the permalink? The code you used would be relevant
   to be able to judge that. Also note that the passed ID should of course be the
   ID of a post.
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [3 years, 11 months ago](https://wordpress.org/support/topic/permalink-123/#post-15796311)
 * You wouldn’t get a post or page slug in the URL because the post and page post
   types don’t use “post” or “page” as query vars, they use “name” or “pagename”
   instead. If you look at the function’s source code, line 346 prevents usage of
   a slug in the URL for posts and pages because `$post_type->query_var` is `false`
   for those types. The function is trying to generate an URL similar to _example.
   com/?custom\_post\_type\_query\_var=custom\_post\_slug_, but the equivalent _?
   post=post\_slug_ would be invalid.
 * If you’re looking for a “pretty” permalink with a post or page slug, this is 
   the wrong function, use `get_the_permalink()` instead.
 *  Thread Starter [WebmasterNYC01](https://wordpress.org/support/users/webmasternyc01/)
 * (@webmasternyc01)
 * [3 years, 11 months ago](https://wordpress.org/support/topic/permalink-123/#post-15796315)
 * this get_post_permalink($post, $leavename = true, $sample = false) is returning
   this [http://localhost/apple/?post_type=page&p=12](http://localhost/apple/?post_type=page&p=12)
 * But i want the frienly post name instead something like this [http://localhost/apple/macintosh](http://localhost/apple/macintosh)
 *  Thread Starter [WebmasterNYC01](https://wordpress.org/support/users/webmasternyc01/)
 * (@webmasternyc01)
 * [3 years, 11 months ago](https://wordpress.org/support/topic/permalink-123/#post-15796326)
 * get_the_permalink($post, $leavename = true) is only returning [http://localhost/apple/](http://localhost/apple/)
   without the page name.
 * I’m looking to return the full url with the page name like this [http://localhost/apple/macintosh](http://localhost/apple/macintosh).
 *  Moderator [threadi](https://wordpress.org/support/users/threadi/)
 * (@threadi)
 * [3 years, 11 months ago](https://wordpress.org/support/topic/permalink-123/#post-15796332)
 * What is your Permalink-setting? [https://wordpress.org/support/article/using-permalinks/](https://wordpress.org/support/article/using-permalinks/)
 *  Thread Starter [WebmasterNYC01](https://wordpress.org/support/users/webmasternyc01/)
 * (@webmasternyc01)
 * [3 years, 11 months ago](https://wordpress.org/support/topic/permalink-123/#post-15796335)
 * get_the_permalink($post, $leavename = true)
 *  Moderator [threadi](https://wordpress.org/support/users/threadi/)
 * (@threadi)
 * [3 years, 11 months ago](https://wordpress.org/support/topic/permalink-123/#post-15796465)
 * This was not the answer to the above question.
 * But another question: why don’t you use [https://developer.wordpress.org/reference/functions/get_permalink/](https://developer.wordpress.org/reference/functions/get_permalink/)?
   There you would get the full path depending on your above mentioned permalink
   settings in the backend.
 *  Thread Starter [WebmasterNYC01](https://wordpress.org/support/users/webmasternyc01/)
 * (@webmasternyc01)
 * [3 years, 11 months ago](https://wordpress.org/support/topic/permalink-123/#post-15796965)
 * post name
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [3 years, 11 months ago](https://wordpress.org/support/topic/permalink-123/#post-15799745)
 * > get_the_permalink($post, $leavename = true) is only returning [http://localhost/apple/](http://localhost/apple/)
   > without the page name.
 * So in your example “apple” is the parent page of the page you want a link to,“
   macintosh?
 * Did you pass a value for $post (ID or WP_Post object)? If so, you likely passed
   the wrong value. If nothing was passed, the global $post variable is apparently
   referring to the parent page instead of the child page you wish to have a link
   for. Without more context it’s difficult to speculate why this would be so.
 * `get_the_permalink()` return is filterable, so one possibility is some other 
   code is erroneously altering the return value for some reason. You could also
   filter “page_link” and force get_the_permalink() to return any link you want,
   but it’d be better to determine why it’s not returning the proper child page 
   link and correct the problem.
 *  Thread Starter [WebmasterNYC01](https://wordpress.org/support/users/webmasternyc01/)
 * (@webmasternyc01)
 * [3 years, 11 months ago](https://wordpress.org/support/topic/permalink-123/#post-15799785)
 * I made my theme from scratch. I am using get_the_permalink($post, $leavename 
   = true) the way is written exactly like this “get_the_permalink($post, $leavename
   = true)”
 *  Thread Starter [WebmasterNYC01](https://wordpress.org/support/users/webmasternyc01/)
 * (@webmasternyc01)
 * [3 years, 11 months ago](https://wordpress.org/support/topic/permalink-123/#post-15799795)
 * correction this is what I am getting back
    this is get_the_permalink($post, $
   leavename = true) returning this [http://localhost/mytheme/%pagename%/](http://localhost/mytheme/%pagename%/)
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [3 years, 11 months ago](https://wordpress.org/support/topic/permalink-123/#post-15802408)
 * What does “mytheme” relate to? Is that your WP installation folder? If so, that’s
   fine.
 * If %pagename% is not replaced by the proper page slug, it indicates that $post
   does not have a proper page ID or WP_Post object. One reason this happens is 
   when we forget to declare `global $post;` within scope of the function call. 
   If the call is within a standard WP loop, you needn’t pass anything. But if you
   do choose to pass a value, it must be the correct value.

Viewing 12 replies - 1 through 12 (of 12 total)

The topic ‘Permalink’ is closed to new replies.

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 12 replies
 * 4 participants
 * Last reply from: [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Last activity: [3 years, 11 months ago](https://wordpress.org/support/topic/permalink-123/#post-15802408)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
