我需要更新所有帖子。我使用批量上传商店,但在网页帖子/产品不显示,当我点击更新,帖子/产品出现。
我认为使用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?
答案 0 :(得分: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;
}
答案 1 :(得分:1)
您应该可以使用WordPress' get_posts
function。尝试:
$all_posts = get_posts('numberposts=');