• I have a number of scheduled posts on my site that are showing as live posts (as I’m using this in an Events section whereby I need scheduled posts to show).

    However it was previously working and showing the correct url i.e. site.com/event/an-event/ but now showing site.com/?post_type=event&p=596

    I can still access the post by with the full url link but any posts that appear on the site have the horrible url.

Viewing 15 replies - 1 through 15 (of 26 total)
  • Are you using a plugin for the events custom post type or did you register it yourself? Under Settings > Permalinks, which option do you have turned on?

    You may want to switch it to default, save, then switch it to “Post Name” and save again. This will refresh the permalinks in case there is some kind of caching you are dealing with.

    Thread Starter greencode

    (@greencode)

    Hi. Yep, done all of that but still the same issue. Basically with “Published” posts the permalink is showing correctly. With “Scheduled” posts that I’m displaying on the live site the url is still as per this example site.com/?post_type=event&p=596

    Is this only happening when you schedule posts with that custom post type or does it also happen if you just schedule a normal post?

    Thread Starter greencode

    (@greencode)

    Exactly the same with regular posts as well i.e. /?p=618

    This wasn’t happening previous to upgrading to 4.2.2.

    It certainly looks like you just need to refresh your permalinks unless you have something going on in your .htaccess forcing the issue. Please try setting permalinks to default > save then set back post name > save again and probably clear your cache or check in a different browser.

    Thread Starter greencode

    (@greencode)

    As previously mentioned I’ve already done that. The htaccess file is showing:

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    # END WordPress

    I have cleared cache, tried in 3 different browsers on two different Macs and still the same. Default permalinks for Future posts, correct permalinks for Published posts.

    Maybe someone else can chime in here, sorry I couldn’t be of more assistance.

    Thread Starter greencode

    (@greencode)

    Thanks for trying.

    I’ve actually just gone through every release since 4.1.3 to see when the problem started to occur and it was 4.2 that it appeared. 4.1.5 was the last working version with the correct permalink structure on “Future” posts.

    Just gone through and deactivated all plugins and still the same issue so this must be a bug with the WP core.

    If you think you found a bug, you can report it using trac.

    https://core.trac.wordpress.org/

    Thread Starter greencode

    (@greencode)

    Did that this morning and it looks like this was changed in 4.2 (https://core.trac.wordpress.org/ticket/30910) so from what I can see there’s no way of displaying a pretty permalink with scheduled/future posts.

    Hi,

    If you want a correct url for your future post, you have to modify this file : /wp-includes/link-template.php, line 160, remove ‘future’ in the array. The is a new value since 4.2 šŸ™

    Before 4.2
    if ( '' != $permalink && !in_array($post->post_status, array('draft', 'pending', 'auto-draft')) ) {

    After 4.2
    if ( '' != $permalink && !in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft', future' ) ) ) {

    The system return the sort url (p=…) if the post status is draft, pending, auto-draft and now future. It’s new since 4.2 and it’s bad for us šŸ™

    My method is not clean, I’ve modified a core file, but it was an emergency.

    Thread Starter greencode

    (@greencode)

    I’ve decided to go down a different route with this, using the custom field to insert the date instead of using the publish date.

    Is greencode correct? “from what I can see there’s no way of displaying a pretty permalink with scheduled/future posts.”

    Surely that can’t be. Since 4.2 all of said posts now show the default permalink. This is a problem for me. I schedule with various social networks before the post goes live, plus use bitlink to get shortened urls. I used to be able to preview the post and see the correct url and could quickly grab that for whatever I need. Now I have to go into edit mode and carefully copy what it “will” be and manually put that in bitlink, in my scheduled newsletter and use for my bulk scheduling on all my social networks. This increased my change of error quite a bit and I’ve had it happen once already.

    Any updates as to if this will be corrected?

    Thanks!
    Nancy

    Moderator keesiemeijer

    (@keesiemeijer)

    Never edit core. It could break your site and every modification will be lost if you upgrade Core anyway.

    If you don’t care that your future post title could be revealed try filtering the permalink on the ‘post_link’ hook in your (child) theme’s functions.php

    add_filter( 'post_link', 'future_permalink', 10, 3 );
    
    function future_permalink( $permalink, $post, $leavename ) {
    	/* for filter recursion (infinite loop) */
    	static $recursing = false;
    
    	if ( empty( $post->ID ) ) {
    		return $permalink;
    	}
    
    	if ( !$recursing ) {
    		if ( isset( $post->post_status ) && ( 'future' === $post->post_status ) ) {
    			// set the post status to publish to get the 'publish' permalink
    			$post->post_status = 'publish';
    			$recursing = true;
    			return get_permalink( $post, $leavename ) ;
    		}
    	}
    
    	$recursing = false;
    	return $permalink;
    }

    btw:
    consider creating a child theme instead of editing your theme directly – if you upgrade the theme all your modifications will be lost. Or create a plugin with the code above.

    Thank You Keesiemeijer.. it works perfectly.

Viewing 15 replies - 1 through 15 (of 26 total)
  • The topic ‘URLs incorrect for scheduled posts’ is closed to new replies.