更新所有 wordpress 帖子
问题描述:
我需要更新我的所有帖子.我为商店使用批量上传,但在网页帖子/产品不显示,当我点击更新时,帖子/产品显示.
I need make all of my posts update. I use bulk upload for store, but in web page posts/products dont show, when i hit update, posts/products are showed up.
我认为使用 wordpress 默认更新功能:
I think use wordpress default update function:
// 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?
But how to get in arrays all posts id?
答
开始吧,您只需使用 foreach 循环浏览帖子即可.
Here you go, you just loop through the posts with a 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;
}