admin管理员组

文章数量:1431904

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?

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?

Share Improve this question edited Apr 15, 2019 at 12:26 Nicolai Grossherr 18.9k8 gold badges64 silver badges109 bronze badges asked Apr 15, 2019 at 11:37 David NguyenDavid Nguyen 1 1
  • 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 Grossherr Commented Apr 15, 2019 at 12:41
Add a comment  | 

1 Answer 1

Reset to default 0

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!

本文标签: Update all WordPress posts39s title and content then display them in a table