我正在我的Wordpress安装中使用自定义post类型,名为“概要文件”。我有一个自定义插件,它创建类型,然后用我希望在CPT的每个实例上可见的内容预填充自定义post类型。见下文:
function profile_content_write() {
$args = array(
'post_type' => 'profiles'
);
$pages = get_posts( $args );
foreach( $pages as $page ){
$post = array(
'ID' => $page->ID,
'post_content' => 'page content...',
);
wp_update_post( $post );
}
}
add_action( 'init', 'profile_content_write' );
但是,有时我需要修改默认内容。虽然使用“概要文件”类型的新帖子将以新内容为特色(如果我更改上面的插件代码),而现有的帖子则不会。
有谁能有效地更新post类型的内容?我很好通过更新插件来修改内容。或者,我很乐意制作一个可以运行更新的菜单项。我只是不知道如何更新内容。
备注:我不想“追加”内容,而是“重写内容”。此外,我将不会写内容在这个帖子类型外,是通过插件功能显示。
发布于 2018-09-24 10:31:01
更新,工作内容
这是通过激活插件文件,然后关闭插件文件来实现的。激活它将重写所有CPT post内容。若要更新内容,请修改插件文件,然后重新激活/停用。
function profile_content_write() {
$args = array(
'post_type' => 'profiles',
'numberposts' => -1
);
$pages = get_posts( $args );
foreach( $pages as $page ){
$post = array(
'ID' => $page->ID,
'post_content' => 'page content...',
);
wp_update_post( $post );
}
}
add_action( 'init', 'profile_content_write' );
https://stackoverflow.com/questions/52459741
复制相似问题