0

Is there a way to update all post at once?

The issue is, when i migrated content from another CMS, some of the permalinks are working fine and some of them are not, when i updated the posts all links are working fine.

I have tried some methods to perform this requirement, but it doesn't helped.

4
  • What exactly do you want to update? A simple WP_Query loop would accomplish your goal. Please post what you have tried so far. Commented Dec 26, 2013 at 7:54
  • There is multiple posts with busted links in the database, when i am clicking on the permalink it returns 404 and when i republish the post the permalink is working well. There is 3000 posts in the database so i need to republish all those posts at once.
    – Nikhil
    Commented Dec 26, 2013 at 8:17
  • Ok, and what's busted? Have you changed something? Migrated to a new url? Why are those links broken? Commented Dec 26, 2013 at 8:38
  • Entire content is migrated from another CMS. So the issue is there only when clicking on some permalinks.
    – Nikhil
    Commented Dec 26, 2013 at 8:40

2 Answers 2

0

Try this out:

/*
Plugin Name: Post Bulk Update
Description: Updates certain fields of my posts at once. On Activation. Awesome
Author: Me. I did it
*/
add_action('init','post_bulk_update');

function post_bulk_update(){
 $posts_to_update = new WP_Query('cat=x&showposts=1000');
while($posts_to_update ->have_posts()) : $posts_to_update ->the_post();
$postUpdateArray = array();
$postUpdateArray ['ID'] = $post->ID;//Don't remove this. The ID is mandatory
$postUpdateArray ['post_title'] = 'Post Prefix: '.$post->post_title;
     wp_update_post( $postUpdateArray );
endwhile;

}

For more reference see this.

1
  • Hey @Rohit Pande the original question didn't provide enough information to actually answer the question. Imo, it would have been beneficial to request clarification to pin point exactly what the problem was. Commented Dec 26, 2013 at 8:40
0

Thanks all,

The issue is resolved by removing special characters from wp_posts -> post_name.

Now all permalinks are working fine.

1
  • Very glad you got it working! Commented Dec 26, 2013 at 8:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.