Make WordPress Core

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#41277 closed defect (bug) (invalid)

Random post returned by get_permalink when on post type archive

Reported by: espellcaste's profile espellcaste Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.8
Component: Permalinks Keywords:
Focuses: Cc:

Description

get_permalink has an odd behavior when on post type archives.

It fetches a radom article from the taxonomy archive, instead of returning the link from the archive itself.

Maybe it was supposed to. But if I do this:

<a class="button" href="<?php echo wp_login_url( get_permalink() ); ?>">

When the link is on a category archive, it will redirect the user to a radom article from that particular category, because the get_permalink is returning that particular random post.

Change History (3)

This ticket was mentioned in Slack in #core by espellcaste. View the logs.


7 years ago

#2 @lopo
7 years ago

  • Resolution set to invalid
  • Status changed from new to closed

I checked and it doesn't return a random post, but the first one of the archive loop, as stated by the documentation:
"Note that when used outside The Loop on a posts page (index, archive, etc.) without the ID parameter, it will return the URL of the last post in The Loop, not the permalink for the current page."

#3 @SergeyBiryukov
7 years ago

  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.