Make WordPress Core

Opened 7 years ago

Closed 4 years ago

#40562 closed defect (bug) (worksforme)

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

Reported by: thefraj's profile thefraj Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.7.4
Component: General Keywords: reporter-feedback close
Focuses: Cc:

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 (7)

#1 in reply to: ↑ description ; follow-up: @thefraj
7 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
7 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
7 years ago

  • Keywords dev-feedback added

#4 @subrataemfluence
7 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
7 years ago

  • Keywords reporter-feedback added; dev-feedback removed

#6 @hellofromTonya
4 years ago

  • Keywords close added

Hello @thefraj,

Does this issue persist today? If yes, please provide us with more details and feedback to help us investigate.

Like @subrataemfluence, I too was not able to reproduce the issue.

For now, I'm marking this ticket as a close worksforme candidate. Why? Not finding this issue reported elsewhere, can't reproduce, and it's been over 4 years since reporter feedback requested. Will review if/when feedback provided.

#7 @hellofromTonya
4 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed

Closing this ticket. However, if the problem persists, please reopen and provide more information to help us further investigate.

Note: See TracTickets for help on using tickets.