我会这样做:
add_action(\'save_post\',\'update_all_meta\');
function update_all_meta($post_id){
// verify if this is an auto save routine.
// If it is our form has not been submitted, so we dont want to do anything
if ( defined( \'DOING_AUTOSAVE\' ) && DOING_AUTOSAVE )
return;
//check for post type
if ( $post->post_type != "YOUR_CUSTOM_TYPE" )
return;
global $post;
$tmp_post = $post;
$args = array(
\'posts_per_page\' => -1,
\'post_type\' => \'YOUR_CUSTOM_TYPE\',
\'post__not_in\' => (array)$post->ID //skip current post
);
$myposts = get_posts( $args );
//loop over all custom posts and update the meta
foreach( $myposts as $post ) {
setup_postdata($post);
update_post_meta($post->ID,\'meta_key\',$meta_value);
}
$post = $tmp_post;
}
但如果存储的数据相同,可以使用options api,这样您只需更新一次,就可以将其用于所有帖子。