• `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)
  • Here you write the function call from https://developer.www.ads-software.com/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

    (@bcworkz)

    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

    (@webmasternyc01)

    this get_post_permalink($post, $leavename = true, $sample = false) is returning this https://localhost/apple/?post_type=page&p=12

    But i want the frienly post name instead something like this https://localhost/apple/macintosh

    Thread Starter WebmasterNYC01

    (@webmasternyc01)

    get_the_permalink($post, $leavename = true) is only returning https://localhost/apple/ without the page name.

    I’m looking to return the full url with the page name like this https://localhost/apple/macintosh.

    Thread Starter WebmasterNYC01

    (@webmasternyc01)

    get_the_permalink($post, $leavename = true)

    This was not the answer to the above question.

    But another question: why don’t you use https://developer.www.ads-software.com/reference/functions/get_permalink/ ? There you would get the full path depending on your above mentioned permalink settings in the backend.

    Thread Starter WebmasterNYC01

    (@webmasternyc01)

    post name

    Moderator bcworkz

    (@bcworkz)

    get_the_permalink($post, $leavename = true) is only returning https://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

    (@webmasternyc01)

    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

    (@webmasternyc01)

    correction this is what I am getting back
    this is get_the_permalink($post, $leavename = true)
    returning this https://localhost/mytheme/%pagename%/

    Moderator bcworkz

    (@bcworkz)

    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.