Here is your code:
if ( isset($_GET['slug-update']) ) {
$posts = get_posts();
foreach($posts as $singlepost) {
if($singlepost->post_status === 'publish'){
$post_id = $singlepost->ID;
$current_slug = $singlepost->post_name;
$updated_slug = $current_slug . '-word';
}
wp_update_post( array(
'ID' => $post_id,
'post_name' => $updated_slug ) );
}
die('Slug Updated');
}
Add this to your theme’s function.php. Then run this with www.example.com/?slug-update
P.S. this will only update the default post type ‘post’ (backup the database to be secure)
Let me know if this helped.
Related Posts:
- remove “index.php” from permalinks
- How to get pretty URLs with add_query_arg in permalinks
- Creating custom permalink structure for languages
- Getting the Site URL Including the Front Base
- How to prevent apostrophes and quotes from appearing in permalinks?
- Update URL Snippet to Canonical Permalink URL
- “.#[random-char-string]” being inserted at end of URLs
- URL Rewrite + Page + Custom Post Type = Unusual Redirect
- Pretty Permalinks
- Remove parent slug for child pages
- How to create a permalink structure for posts in a specific category
- How to Remove Slug From Database?
- How to make draft posts or posts in review accessible via full url / slug?
- Remove subfolders from URL
- Remove parent slug for child pages
- Limiting the number of words or characters in the slug/permalink
- flexible rewrite ‘ramble’ URLs with WordPress
- Custom rewrite rules for feeds of custom queries (query_var query strings in URL)?
- Make attachment pages require a base url
- How to Modify Existing Rewrite Rules?
- custom permalink/shortlink with base62 encoded post ID
- Change author slug and functionality
- How to reset canonical URLs / fix redirect loop
- How can I add a page’s ID to its permalink using WP_Rewrite?
- Change blog segment of URL
- Non latin post slug truncate
- Force wordpress to display page with same url structure as categories
- Share same Slug for a Custom Post Type and 2 Taxonomies
- How can i have a custom post type with more slugs for each post?
- URL rewriting: removing the site’s basename for a specific category
- Pre-populate Slug / Permalink with URL
- mod-rewrite exception? keep #hash in matching urls?
- wordpress how to replace url /bar with foo/bar for custom post type
- Remove parent page from url
- Suddenly new posts have the default permalink instead of the post name
- Getting back a permalink from custom url
- add_rewrite_rule – Page Slug from “/foo-bar/” to “/foo/bar/”
- Access posts while mod_rewrite is broken
- Remove international characters from slug – Almost done – Bit help
- Can I change the URL structure for a CPT only?
- How to remove slug from front page?
- How do I structure my permalinks in WordPress?
- A different permalink structure for different categories
- assets aren’t loading on a page but loads on others? slug permalink conflict?
- Multiple Taxonomy Items for Separate URLs
- WordPress keeps removing query var from the URL
- How to construct a dynamic rewrite rule for child pages that passes more than one query var
- Using a template file for a specific custom URL
- Extra url paths as variable
- Passing parameter through permalink structure
- How to create a standard WP Page that has the same url as an archive
- rebuilding/ rewriting a url to make it SEO friendly
- a way to support totally different url structure
- How to change URL of my pages?
- Custom Permalink Base
- Include language variable in url
- How to get the perfect WordPress, WooCommerce, Custom Post Type pretty permalinks?
- Best way to approach creating a sitemap with unique URLS (No Permalink Changes)
- How to Stop WordPress Change Slug Automatically Same as Title When Publish?
- Get Page URl when changing slug and permalink
- Can’t Remove Unnecessary Slug
- Is it possible to get a page link from its slug?
- Need help with add_rewrite_rule
- How do I add /blog/ as a prefix to permalink structure for blog posts, tag pages, etc.?
- How does WordPress create URLs that Apache knows about?
- Passing and retrieving query vars in wordpress
- Stop WordPress appending `-2` to the end of my url after i change it
- Get default permalink structure from pretty URL’s
- Permalink format: singular or plural
- Add .html (dot HTML) extension to custom post types
- Get current URL (permalink) without /page/{pagenum}/
- How does WordPress handle permalinks?
- Pretty permalinks for search results with extra query var
- WordPress slug issue with non-latin characters
- Using custom/dynamic “slug” for a page
- Custom post type permalink endpoint
- How to remove dates from existing permalinks?
- Using $_GET variables in the URL?
- Removing the redirect after changing a page’s slug
- Must slugs be unique?
- How to use relative links on my pages?
- How does wordpress keep track of post id when post id is not used in permalinks?
- Stop WordPress from reserving slugs for media items?
- Including category-base in a post permalink results in 404
- Change slug on post creation
- WordPress Permalink changes to question mark (?) in URL
- WordPress thinks my custom route is a 404
- Prevent WordPress from abbreviating-long-slugs…-in-the-admin
- Adding another word in front of post url
- Post type child of another post type
- Display posts with author in the url with custom post types
- Date based URLs for custom posts and pagination
- Removing hierarchical pages in the permalink
- How to add a custom URL placeholder to author archives?
- Multiple post categories – single permalink
- How to custom change author base without $this->front?
- URL rewrite based on a custom field value
- Why don’t WordPress post slugs allow accents?
- Is It A Good Idea To Change Author Slug (user_nicename field) Directly In MySQL DB?
- How to prevent the default home rewrite to a static page