Make WordPress Core

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#40227 closed defect (bug) (invalid)

shortlink shows POST instead of PAGE guid

Reported by: darko-a7's profile Darko A7 Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.7.3
Component: Posts, Post Types Keywords:
Focuses: Cc:

Description

original forum topic is here:
https://wordpress.org/support/topic/shows-post-url-form-instead-for-page/

In short: created "page" inside WP Admin > Pages menu, and in it's source code the shortlink displayed is wrong (using form for posts, instead of pages):

wrong:

<link rel='shortlink' href='https://mywebsite.com/?p=995' />

correct:

<link rel='shortlink' href='https://mywebsite.com/?page_id=995' />

proposed fix:
https://wordpress.org/support/reply/8941661/

original code:

if ( 'page' === $post->post_type && $post->ID == get_option( 'page_on_front' ) && 'page' == get_option( 'show_on_front' ) ) {
$shortlink = home_url( '/' );

should be:

if ( 'page' === $post->post_type ) {
$shortlink = home_url( '?page_id=' . $post_id );

No longer get 404 from the shortlink url @ page's source code.

Thanks!

Change History (8)

#1 @dd32
7 years ago

Hi @Darko-A7 and welcome to Trac,

This is by design - ?p=123 will redirect to the correct location for post_id 123 regardless of if it's a post, page, attachment or custom post type.

If you're not seeing that redirect happen for you, it sounds like there's something else at play here preventing that, and that's what you should be looking at for debugging.

For reference, here's a live site performing as expected: https://dd32.id.au/?p=8319 (redirects to the page)

#2 @Darko A7
7 years ago

Hi dd32,

Thanks for your reply!

I have checked my php log and there are 0 notices/warnings etc (and enabling WP_DEBUG/WP_DEBUG_LOG naturally also gave me an empty file without any issues).

As posted @ forum, all the fields in database seems to be correct, including page's GUID, which is in the form of https: / / website.com?page_id=xxx

Not sure really why it is no working, and this is the only "page" I have for now. It is a standard apache server with auto-generated .htaccess file, using predefined permalinks structure (which do work fine, btw). A real puzzle :(

With above modification it works as expected.

I have also tried to change page's GUID inside database to the form https: / / website.com?p=xxx, but it did not work.

#3 @dd32
7 years ago

The guid isn't used for this at all - and no server configurations should affect it. My best guess is that it'd be related to a custom plugin or theme in use.

#4 @Darko A7
7 years ago

Thanks, strange I have now tested on local server with same theme and most plugins, and it is working there.

I will try to create new page, delete this one, and see if it will work.

#5 @SergeyBiryukov
7 years ago

  • Component changed from General to Posts, Post Types

#6 @Darko A7
7 years ago

Well, thanks dd32, I have located the plugin which was causing the issue - Smart404 (yes, I know it is very old, but it still actually works and I have reworked minor portion of the code to be compatible with latest WP versions). It seems that it will need some more refinements :)

Closing this issue as it is not related to the WP core.

Thanks!
Regards

#7 @Darko A7
7 years ago

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

#8 @SergeyBiryukov
7 years ago

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