If you just need to change the post content, you can avoid the overhead of get_posts/WP_Query by directly querying the database:
global $wpdb;
$results = $wpdb->get_results("SELECT ID, post_content FROM {$wpdb->posts}");
$total = count($results);
$changed = 0;
foreach($results as $entry){
$new_content = strip_tags($entry->post_content, '<img><a>');
if($entry->post_content !== $new_content){
$wpdb->query($wpdb->prepare(
"UPDATE {$wpdb->posts} SET post_content = %s WHERE ID = %s)",
$new_content, $entry->ID));
$changed++;
}
}
printf("Changed %d out of %d posts", $changed, $total);
(back-up db first)
Related Posts:
- Import and replace existing page/post content
- Python circular importing?
- Where does the Media Library live in the database?
- How to import wordpress posts with images from one wordpress site to another?
- What is the required format for importing posts into WordPress?
- What exactly does the import tool do?
- WordPress Theme Options Import/Export
- How to add featured thumbnail into import XML?
- Why do I lose all the slashes, i.e., ” \ “, in my blogs when I import XML files by the WordPress Importer plug-in?
- WordPress Import shows an error when uploading previously exported xml file
- Disabling HTML Filtering When Importing Into WordPress Multisite
- Migrating WP site to another URL
- Import old SQL dump into new WordPress version
- How to migrate a WordPress installation from one site to another, including all images?
- What server settings are required to import WordPress XML file
- How to completely export and import WordPress?
- Import a very old WordPress Version into new WordPress
- WXR import problem — not including categories
- Is there a way to trigger an automatic import of a WP backup on creation of a new WP multisite site?
- Download/View Schema (or DTD) for XML Import
- GUID not updated on import
- How to import a TypePad blog including all media?
- Easy way to import a post from Word?
- Importing large data from blogger
- Scrape data from a website and post it on the blog
- Faking the “onSave” event
- Importing custom post types using WordPress Importer, how to check for meta field values
- Is there a way to import Blogger into bbPress?
- What can I expect when moving from a hosted (WordPress.com) blog to one hosted by Page.ly
- can’t import xml file
- WP CLI not importing media files
- Importing XML to WordPress, permalink problem
- Error: Failed to import tag/post
- How to get and save WordPress content (html, css, images, videos) from a Java program?
- Update Attached Image Size after Import
- WordPress does not import all pages and post
- Programmatically save one/any post
- How to add more names in Baby Name Page?
- Batch attach unattached images
- Export + Import = wrongly duplicated content
- Is there a way to import a folder of HTML files into the blog?
- Using WordPress Importer, how to import media only?
- A question on WXR
- Problems with WordPress Import
- What is basic structure of xml for importing a page in wordpress?
- How to import content from WordPress.com to a self hosted WordPress installation?
- In What WordPress Version Was the Import/Export Tool Introduced?
- Shows 1400 post published but don’t see them
- how to import a custom website into WordPress
- How to import Theme Unit Test on localhost
- WXR xml files are being imported as a TXT files and showing up under ‘Media’
- WordPress WXR import – importing a large file
- Import HTML/JS post to WordPress?
- Is it possible to import several xml from different sites to another?
- After imorting posts from another blog double line breaks have been replaced with single line breaks
- Import post from XML files into custom post type programatically [closed]
- how do i import a site given that i have [domain].sql and a folder of site files? [closed]
- WordPress: Updating via Import
- Export Users From Live Site to Import onto staging
- create importer with importer api [closed]
- Import subdomain WordPress into main domain WordPress
- Exporting featured image
- CSV to WordPress posts: do I have to populate each possible field?
- How to add biography of user while importing?
- Programatticaly Import Pages while Maintaining Hierarchy
- product export and import using xml
- Importing a database from a custom built CMS to WordPress
- Is there a way to show different source feeds on individual pages?
- Export WordPress from one domain to another domain
- automated import from blogger
- How to import media from folder as opposed from old site?
- How to correctly move jquery script to external file
- Import function loses tags
- Upgrading to WP 5+ with block content – Export & Import Page Content
- Existing posts hidden after WP import
- Importing a Google Group to bbPress
- Import large database in php my admin
- Error importing website: “There has been a critical error on your website.”
- After importing items are not displaying
- How to import posts correctly?
- Mixed Content: The page at ” was loaded over HTTPS, but requested an insecure font ”
- WordPress importer – How to handle id clashes for featured images
- Pull specific data from CSV
- Merge two wordpress sites
- Import demo data into wordpress template
- XML file import for attachments or featured images
- XML importing fails
- How to do one-off import or data migration?
- WordPress import error
- Max execution time error with stream_body() in wp-includes/class-http.php
- Importing demo content from plugin
- Standard wordpress importer seems to be missing blog images
- Migrate bbpress content to posts
- Moving 2 wordpress sites to one
- How to import data from Mingle Forum plugin to bbPress?
- Export plugin omits many images
- Failed Media Import (importing from LIVE to local)
- Import post from Tumblr to WordPress [duplicate]
- Syndicate posts to another blog?
- WordPress Export/Import for custom options.php values?