change permalink number
Question
these days I wonder how I can change the final permalink number of my posts by +1, i found this code on the net, but it needs to be changed someone help me?
// Get all posts
$query = new WP_Query(array(
'post_type' => 'post',
'posts_per_page' => -1,
));
$posts = $query->get_posts();
foreach ($posts as $post) {
// Get permalink
$url = $post->post_name;
// old url
$old_url = array(
'http://localhost:8888/site/testpermalink-1/',
'http://localhost:8888/site/testpermalink-1/',
'http://localhost:8888/site/testpermalink-7/',
'http://localhost:8888/site/testpermalink-4/',
'http://localhost:8888/site/testpermalink-36/',
);
// Replacement
//$replacement = '';
// Replace url
//$new_url = str_replace($old_url, $replacement, $url);
// Prepare arguments
$args = array(
'ID' => $post->ID,
'post_name' => $new_url,
);
// Update post
wp_update_post( $args );
}
}
I would like this list to be changed with the final number +1, so this list after editing should be:
$new_url = array(
'http://localhost:8888/site/testpermalink-2/',
'http://localhost:8888/site/testpermalink-2/',
'http://localhost:8888/site/testpermalink-8/',
'http://localhost:8888/site/testpermalink-5/',
'http://localhost:8888/site/testpermalink-37/',
);
however then these permalinks should be automatically saved after you change them.
0
1 month
0 Answers
12 views
0
Leave an answer
You must login or register to add a new answer .