WordPress.org

Make WordPress Core

Opened 2 years ago

Last modified 2 years ago

#40562 new defect (bug)

get_permalink($id) and get_permalink($id) get_post_permalink ($id) Return current page Url, not Url of requested ID

Reported by: thefraj Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.7.4
Component: General Keywords: reporter-feedback
Focuses: Cc:
PR Number:

Description

If I had a page (say) ID = 4 and then did:

<a href="<?php echo get_post_permalink(4); ?>">the link</a>

this will return the link to the current page, not the link of page ID = 4

Your documentation suggests it would return the Url of page ID = 4 as detailed here https://developer.wordpress.org/reference/functions/get_post_permalink/

Change History (5)

#1 in reply to: ↑ description ; follow-up: @thefraj
2 years ago

Sorry, the title should have read:

get_post_permalink($id) and get_permalink($id) this bug affects both of these methods where it is not possible to obtain a Url of the requested page or post Id

Replying to thefraj:

If I had a page (say) ID = 4 and then did:

<a href="<?php echo get_post_permalink(4); ?>">the link</a>

this will return the link to the current page, not the link of page ID = 4

Your documentation suggests it would return the Url of page ID = 4 as detailed here https://developer.wordpress.org/reference/functions/get_post_permalink/

#2 in reply to: ↑ 1 @bhargavbhandari90
2 years ago

Hi there,
get_post_permalink will give result only for custom post types. Try to check if you are passing the CPT's id.

Replying to thefraj:

Sorry, the title should have read:

get_post_permalink($id) and get_permalink($id) this bug affects both of these methods where it is not possible to obtain a Url of the requested page or post Id

Replying to thefraj:

If I had a page (say) ID = 4 and then did:

<a href="<?php echo get_post_permalink(4); ?>">the link</a>

this will return the link to the current page, not the link of page ID = 4

Your documentation suggests it would return the Url of page ID = 4 as detailed here https://developer.wordpress.org/reference/functions/get_post_permalink/

#3 @bhargavbhandari90
2 years ago

  • Keywords dev-feedback added

#4 @subrataemfluence
2 years ago

@thefraj I could not reproduce the issue. Tried by adding your snippet with my own custom Post ID

<a href="<?php echo get_post_permalink(717); ?>">the link</a>

and

<a href="<?php echo get_permalink(717); ?>">the link</a>

in a detail page of another custom post type (single-hotel.php).
In both occasions correct permalink for post ID 717 were generated.

#5 @SergeyBiryukov
2 years ago

  • Keywords reporter-feedback added; dev-feedback removed
Note: See TracTickets for help on using tickets.