Is there any setting or workaround to set this other than making an /events-2/ page?
]]>For example, if you go to https://space.nss.org/renew
Instead of getting a 404, WordPress delivers the page https://space.nss.org/renewable-energy-partnership/
What on Earth is WordPress thinking?
What can I do to fix this?
]]>-2
appended to the ID. You can see the Post Name in the database with the same value.
In other words, it looks like this:
https://example.com/123-2
instead of
https://example.com/123
How can I fix the ability to create new posts without titles to also not have the appending characters?
]]> $update_slug = array(
'ID' => $post_id,
'post_name' => get_the_title( $post_id )
);
wp_update_post( $update_slug );
Thanks for some clearing answers,
Cheers,
Denis
Charles Kelly
]]>I am trying to modify a plugin to put the year+title as the post_name. As I go though and manually post the old results, I would like to have the URL read like this: https://www.striders.net/race-results/2012-resolution-run-8k-prediction-run The plugin code does work, but I have to click Update twice. The first time I click Update it always sets the year as 2016 (the current year). The second time I click Update it will pull the ‘publish-on’ date and for example will set the year to 2012 if I set the publish-on date to 2012. Why does $thePost->post_date not have the correct value of 2012 the first time I click Update? Why it does $thePost->post_date have the correct value of 2012 the second time through? Is there a different method other than save_post that I should be hooking or a different date value that I can pull? It seems like the date on the post is automatically set to the current year, and then after the save the date is then updated to 2012.
The reason I am doing this is because I am posting a bunch of old race results and would like to have the dates appear in the past.
Here is the plugin code:
<?php
add_action( 'save_post', 'rewrite_post_name' );
function rewrite_post_name( $post_id) {
if ( ! wp_is_post_revision( $post_id ) ) {
remove_action( 'save_post', 'rewrite_post_name' );
$thePost = get_post();
if ($thePost->post_type === 'post') {
$post_name2 = substr($thePost->post_date, 0, 4) . " " . $thePost->post_title;
wp_update_post( array(
'ID' => $post_id,
'post_name' => $post_name2 // Rewrite based on Post Title
));
}
add_action( 'save_post', 'rewrite_post_name' );
}
}
?>
]]>I am using the TwentySixteen theme, and have page.php and footer.php open in an editor. When I output $post->post_name in page.php, it shows ok, but when I output the same in footer.php, I get the title of the earliest post to the WP News Bulletin. Can someone help me understand why this happens?
Thanks.
]]>I know that recently, WP have changed /%post_name%/ which is when the problem started?
Anyone know anything about this and a fix please?
Many Thanks
]]>Some of my posts have links to other posts which are in the form of …/notebooks/201504221200.html and I figured that if the slug were the same date and time, then changing the links would be a simple matter of removing the “.html” and possibly adding a trailing slash. But the post_name doesn’t seem to work at all.
Here’s a sample:
<item>
<title>So I went to traffic school. </title>
<post_date>1999-08-02 12:00:00</post_date>
<post_name>199908021200</post_name>
<pubDate>Mon, 02 Aug 1999 12:00:00 PST</pubDate>
<post_author>sinasnet</post_author>
<content:encoded>My boring ramblings deleted to preserve your sanity</content:encoded>
</item>
The original site is here and the new one is here.
Thanks for any help!
]]>