I am trying to update all the WP post title and content then show the just updated post to a table. I am using the following code but it does not work:

$args = array( 
  'post_type' => 'post', 
  'numberposts' => -1 
$myposts = get_posts($args); 
foreach ($myposts as $mypost){ 
  $mypost->post_title = $mypost->post_title.'test'; 
  wp_update_post( $mypost ); 
  echo "<td>".$mypost->post-title.""."</td>";

Also, as I am trying to update all the posts which might have timeout error or server timeout. How to display this action with AJAX or jQuery or anything to perform one by one then sleep?

  • It does not work is not a good descriptor, and not that well received, it's better to be more specific. After all, you want people to take time out of their day to help you, so better be forthcoming. Additionally, a question is supposed to contain one specific problem, so answers are clearly aimed at that. It's not a problem to ask multiple questions, and link to the other ones, but make their quality good. To get familiar with the guidelines of this community give the help center sections regarding those a good read.
    – Nicolai
    Apr 15 '19 at 12:41

For a process this large you are probably running up against timeout errors. You can either set your server's timeout to a very, very large number (not recommended) or use a different process to achieve these results.

Take a look at writing a command using WP CLI or adding a scheduled task to allow the server to run these in the background.

You may have to handle which posts have already been updated and skip those if this process needs to occur more than once.

Best of luck!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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