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

How to generate slugs?

As @toscho already answered here, yes this is possible. You just need to copy this code into the functions.php of your theme, and there you go. // get all posts $posts = get_posts( array ( ‘numberposts’ => -1 ) ); foreach ( $posts as $post ) { // check the slug and run an update … Read more

Update post date on every new comment?

From what i understand, you want to change the post’s modification time whenever a comment is left on your post. For this, you need to hook into the wp_insert_comment hook and update the post’s date manually: add_action(‘wp_insert_comment’,’update_post_time’,99,2); function update_post_time($comment_id, $comment_object) { // Get the post’s ID $post_id = $comment_object->comment_post_ID; // Double check for post’s ID, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)