What does wp_update_post() do that the $wpdb class does not?

wp_update_post() calls some hooks that $wpdb doesn’t on it’s own. You’ll have to do it on your own to make it compatible with other plugins. wp_update_post() calls some functions related to database entry sanitation, thumbnails, attachments, time (format, zone etc.), comment, taxonomy, meta, cache etc. So if you use $wpdb, make sure you handle all … Read more

Mass Update lines of code for all posts

This script will get all posts and replace it content according to your needs: function wpse_287574_replace_content() { // Get all posts $query = new WP_Query(array( ‘post_type’ => ‘post’, ‘posts_per_page’ => -1, )); $posts = $query->get_posts(); foreach ($posts as $post) { // Get content $content = $post->post_content; // Regex and replacement $regex = ‘/^(\<a\s+data-name=\”.+\”)(\>(.+)\<\/a\>)$/’; $replacement=”$1 href=”https://wordpress.stackexchange.com/items/?item=”$2″; … Read more

bulk post_content update

This is what I mean: <?php $tochange = get_posts(‘numberposts=-1&post_type=any&category_name=category-name-you-want-to-change’); foreach($tochange as $post){ setup_postdata($post); $contentchange=””; /*here you do the magic, string replace or whathever you want to do*/ $tochange = array(); $tochange[‘ID’] = $post->ID; $tochange[‘post_content’] = $contentchange; $out = wp_update_post($tochange); unset($tochange); } wp_reset_query(); ?>

Error in WP_update_post

The key to using WordPress outside of WordPress is include the wp-load.php file: So your code will like: <?php // Include the wp-load’ include(‘YOUR_WP_PATH/wp-load.php’); // Update post 1 hello word $my_post = array( ‘ID’ => 1, ‘post_title’ => ‘This is the updated post title.’, ‘post_content’ => ‘This is the updated content.’, ); // Update the … Read more