更新所有wordpress帖子

更新所有wordpress帖子,wordpress,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_upda

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

我认为使用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 );
但是如何获取数组中的所有帖子id

您应该能够使用。尝试:


给你,你只需用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;
}
/*
插件名称:示例
描述:这不仅仅是一个插件,它是代码。。
作者:
*/
添加动作('init','example_hide');
函数示例_hide(){
$my_posts=get_posts(数组('post_type'=>post','numberposts'=>10));
foreach($myu post作为$myu post):
$my_post['post_content']='这是更新的内容';
wp_update_post($my_post);
endforeach;
}

这似乎对我不起作用,但我将在init hook上尝试,正如您目前所显示的,我正在管理菜单页面回调中进行。我使用它来重新保存我的所有CPT(这是根据自定义表中的数据构建地图所需的)-我使用了它,它工作得很好,但是,我删除了$my_post['post_content']因此,不会更新帖子信息。这对我有用。请确保刷新页面以使其运行。感谢rockmandew,作为说明,我通常在插件中插入此类代码。这就是标题的作用。激活,等待,停用,你就完成了~!这种方法将“一次性”代码保留在模板或主题之外。我不明白做foreach和wp_update_post和点击update按钮有什么不同。
/*
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;
}