Opened 10 years ago
Last modified 5 years ago
#32322 assigned defect (bug)
Custom permalink structure incorrect for Future posts
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | Future Release | Priority: | normal |
Severity: | normal | Version: | 4.2 |
Component: | Permalinks | Keywords: | has-patch needs-testing has-unit-tests needs-dev-note |
Focuses: | Cc: |
Description
From V4.2 there is a bug with custom permalink structures used for Future posts that are visible on the front end.
Example:
- You have your custom permalink structure set up as "Post name".
- "Published" posts show up with the correct permalink structure i.e. mysite.com/single-post/
- "posts marked as "Future" but visible in the front end (i.e. if you're wanting to show posts that are scheduled) show up with the default permalink structure i.e. mysite.com/?p=618
Rolling back through the versions of WordPress, all was working correctly in v4.1.5 and then stopped working from v4.2
Attachments (5)
Change History (28)
#1
@
10 years ago
- Summary changed from Default permalink structure showing for Future posts to Custom permalink structure incorrect for Future posts
#3
follow-up:
↓ 4
@
10 years ago
Thanks for the quick reply. I've had a look at the link you sent but and whilst that appears to be exactly the issue I'm talking about, I'm unsure how to rectify the issue so that the pretty permalink is shown instead of the default permalink. I'm using
<?php the_permalink(); ?>
to generate the link.
#4
in reply to:
↑ 3
@
10 years ago
Hi, I'm in the same boat as @greencode. I'm unclear how to modify our pages to workaround this change. We have an events page that is now showing the numeric permalink for future events, both as a result of the_permalink() as well as the {PERMALINK} shortcode used in a widget.
How should I be modifying our pages to show the "pretty" permalink?
Thanks.
Replying to greencode:
Thanks for the quick reply. I've had a look at the link you sent but and whilst that appears to be exactly the issue I'm talking about, I'm unsure how to rectify the issue so that the pretty permalink is shown instead of the default permalink. I'm using
<?php the_permalink(); ?>to generate the link.
#5
follow-up:
↓ 6
@
10 years ago
- Keywords needs-patch good-first-bug needs-unit-tests added
- Type changed from defect (bug) to enhancement
There isn't a simple way to do it. Maybe we need a filter around the array of post statuses in the get_permalink()
function to control which statuses get a pretty permalink.
#6
in reply to:
↑ 5
@
10 years ago
Howdy,
@johnbillion, you made it too easy! :) Here's an initial patch, just to see how this looks. Hope i'm doing this right...
I swapped the if and else here -- it seemed to make sense asking "should we use a short link" instead of "should we not use a fancy link."
Besides the several opportunities in get_permalink
to clean up the code style, how's this look?
#7
@
10 years ago
- Type changed from enhancement to defect (bug)
I have the same problem with the post status,
i updated the link-template with the patch above but this is nog working for me.
For the post i'm using custom post type ui plugin, needs this a other patch to fix it ?
#8
@
10 years ago
hi @kreatif,
With this patch, you would need to add a filter to your theme. Something like,
add_filter( 'shortlink_post_statuses', 'prettylink_future_posts' ); function prettylink_future_posts( $post_statuses ) { $future_index = array_search( 'future', $post_statuses ); unset( $post_statuses[ $future_index ] ); return $post_statuses; }
#9
@
10 years ago
- Keywords has-patch added; needs-patch removed
This is probably the best approach.
The filter will need inline filter documentation and some more unit tests along with those in the Tests_Link
class.
#10
@
10 years ago
- Added inline filter docs.
- Added the filter to
get_post_permalink
, which i missed at first. - I also spent a moment creating unit tests; it feels a bit overly verbose -- is this making sense?
On that note, there's a bit of duplication going on in here, this piece:
$statuses_which_should_shortlink = apply_filters( 'shortlink_post_statuses', array( 'draft', 'pending', 'auto-draft', 'future' ) );
It was already duplicated, and now with the filter it's a touch longer. Does it make any sense pulling this out into a function?
#11
@
10 years ago
@kdool, Thanks, works like a charm
I've one bug that is related to this, but don't know if this is a wordpress bug or custom post type ui bug;
When i click on a post i get a blank page (with post status => furure).
Two other post types with post status => published dont't have this problem
Error that i get: Failed to load resource: the server responded with a status of 404 (Not Found)
When i'm visiting the post via edit post -> view post, i can see the post
#12
@
10 years ago
@kreatif, formatting the permalink is one thing, but enabling non-logged in users to view future posts is another. I did a very quick search and found this plugin, which seems to work by doing the following:
add_filter( 'the_posts', 'show_future_posts' ); function show_future_posts( $posts ) { global $wp_query, $wpdb; if ( is_single() && $wp_query->post_count == 0 ) { $posts = $wpdb->get_results( $wp_query->request ); } return $posts; }
#13
@
10 years ago
- Resolution set to worksforme
- Status changed from new to closed
@kdoole Thanks the add filter code solved the problem.
I didn't kwow about the non-logged users can see the future posts.
Learned something new, Thanks!
#16
@
10 years ago
There's further inconsistency here. For a scheduled post, the permalink used in various places is inconsistent.
- On the post listing screen, the 'View' link looks like
example.com?p=123&preview=true
- On the post editing screen, the 'View Post' link in the admin toolbar looks like
example.com?p=123
- On the post editing screen, the 'View Post' button next to the slug editor is the pretty permalink
Whichever URL you view the post at, the is_preview()
conditional is true, so the non-pretty links should always be in the format example.com?p=123&preview=true
.
#17
in reply to:
↑ description
@
8 years ago
Is there any progress on this? Still seems to be an issue.
#18
@
6 years ago
- Keywords needs-refresh added; needs-unit-tests removed
- Milestone changed from Awaiting Review to 5.3
This patch still works and while it doesn't solve everything, as @johnbillion noted four years ago, it does add a good filter instead of the hardcoded statuses as they are now:
if ( '' != $permalink && ! in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft', 'future' ) ) ) {
I wouldn't change anything else though, except run that array through a filter twice. Wouldn't need to rename the $draft_or_pending
var nor change the conditional at line 159.
/** * Filters the list of post statuses which should use shortlinks and avoid fancy permalinks. * * @since 4.3.0 * * @param array $statuses The list of statuses */ $auto_short_link_statuses = apply_filters( 'shortlink_post_statuses', array( 'draft', 'pending', 'auto-draft', 'future' ) ); if ( '' != $permalink && ! in_array( $post->post_status, $auto_short_link_statuses ) ) {
and later in the file just:
$auto_short_link_statuses = apply_filters( 'shortlink_post_statuses', array( 'draft', 'pending', 'auto-draft', 'future' ) ); $draft_or_pending = get_post_status( $post ) && in_array( get_post_status( $post ), $auto_short_link_statuses );
and that's that.
There still is the issue with the inconsistency of preview link but it is a separate issue.
This ticket was mentioned in Slack in #core by sergey. View the logs.
6 years ago
This ticket was mentioned in Slack in #core by pento. View the logs.
5 years ago
#21
@
5 years ago
- Keywords needs-testing has-unit-tests needs-dev-note added; good-first-bug needs-refresh removed
https://core.trac.wordpress.org/attachment/ticket/32322/32322.diff
I have refreshed the patch with the noted from my previous comments. Not sure of what adding a new filter needs to have done other than the code comments. Also, some more testing would be nice.
Hi @greencode, welcome to Trac!
Looks like this was an intended change in #30910.