bulk_edit_posts
云策文档标注
概述
bulk_edit_posts 是一个 WordPress 动作钩子,在批量编辑文章数据处理后触发,允许开发者执行自定义操作。它接收更新后的文章ID数组和共享文章数据作为参数。
关键要点
- 钩子名称:bulk_edit_posts,在 WordPress 6.3.0 版本引入
- 触发时机:在批量编辑文章数据处理完成后执行
- 参数:$updated(更新文章ID数组)和 $shared_post_data(共享文章数据关联数组)
- 相关函数:bulk_edit_posts() 用于处理批量编辑文章数据
代码示例
// Define a custom function to handle bulk edit
function my_bulk_edit_posts_handler( $updated, $shared_post_data ) {
// Loop through the array of post IDs that have been updated
foreach ( $updated as $post_id ) {
// Perform custom actions on each post
// For example, you can update post content or metadata
$post_title = get_the_title( $post_id );
$new_content = "Updated content for post: $post_title";
// Update post content
wp_update_post(
array(
'ID' => $post_id,
'post_content' => $new_content,
)
);
// You can access $shared_post_data here as well if needed
}
}
// Hook the custom function to the 'bulk_edit_posts' action
add_action( 'bulk_edit_posts', 'my_bulk_edit_posts_handler', 10, 2 );
原文内容
Fires after processing the post data for bulk edit.
Parameters
$updatedint[]-
An array of updated post IDs.
$shared_post_dataarray-
Associative array containing the post data.
Source
do_action( 'bulk_edit_posts', $updated, $shared_post_data );
Changelog
| Version | Description |
|---|---|
| 6.3.0 | Introduced. |
Skip to note 2 content
Huzaifa Al Mesbah
// Define a custom function to handle bulk edit function my_bulk_edit_posts_handler( $updated, $shared_post_data ) { // Loop through the array of post IDs that have been updated foreach ( $updated as $post_id ) { // Perform custom actions on each post // For example, you can update post content or metadata $post_title = get_the_title( $post_id ); $new_content = "Updated content for post: $post_title"; // Update post content wp_update_post( array( 'ID' => $post_id, 'post_content' => $new_content, ) ); // You can access $shared_post_data here as well if needed } } // Hook the custom function to the 'bulk_edit_posts' action add_action( 'bulk_edit_posts', 'my_bulk_edit_posts_handler', 10, 2 );