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 | 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:
↓ 2
@
7 years ago
#2
in reply to:
↑ 1
@
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/
#4
@
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.
#6
@
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.
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: