更新所有wordpress帖子

Fox*_*sk8 4 wordpress

我需要更新我的所有帖子.我使用批量上传商店,但在网页帖子/产品不显示,当我点击更新,帖子/产品出现.

我认为使用wordpress默认更新功能:

// Update post 37
  $my_post = array();
  $my_post['ID'] = 37;
  $my_post['post_content'] = 'This is the updated content.';

  // Update the post into the database
  wp_update_post( $my_post );
Run Code Online (Sandbox Code Playgroud)

但是如何在数组中获取所有帖子ID?

Dig*_*nDj 12

在这里,您只需使用foreach循环播放帖子.

/*
Plugin Name: Example
Description: This is not just a plugin, it's <em>CODE</em>..
Author: 
*/
add_action('init','example_hide');

function example_hide(){

    $my_posts = get_posts( array('post_type' => 'post', 'numberposts' => 10 ) );

    foreach ( $my_posts as $my_post ):

    $my_post['post_content'] = 'This is the updated content.';

    wp_update_post( $my_post );

    endforeach;
}
Run Code Online (Sandbox Code Playgroud)