更新所有 wordpress 帖子 [英] Update all wordpress posts
本文介绍了更新所有 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;
}
这篇关于更新所有 wordpress 帖子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文