其中一个解决方案:
在插件中,您在其激活时创建一个选项,以存储您的序列号:
/*
Plugin Name: Reservation Increment
Description: test
*/
/**
*
* Name : myplugin_activate
* Description : Activation function
*
* @params
* @return
*
**/
function myplugin_activate() {
update_option(\'reservation_increment\',3000);
}
register_activation_hook( __FILE__, \'myplugin_activate\' );
现在,您必须更新该值,并在创建新预订时将其与新CPT关联:
/**
*
* Name : update_reservation_sequence
* Description : Updates the reservation unique incremential number
*
* @params
* @return
*
**/
function update_reservation_sequence ($post_id, $post, $update){
$slug = \'reservation_cpt\';
// If this isn\'t a \'reservation_cpt\' post, don\'t update it.
if ( $slug != $post->post_type || $update) {
return;
}
$increment = get_option(\'reservation_increment\') +1;
if ( ! add_post_meta( $post_id, \'reservation\', $increment, true ) ) {
update_post_meta ( $post_id, \'reservation\', $increment );
}
update_option(\'reservation_increment\',$increment);
return;
}
add_action( \'save_post\', \'update_reservation_sequence\',10,3 );
然后,在您的单个预订中访问它。php模板:
echo "<p>Reservation number : ".get_post_meta( get_the_ID(), \'reservation\', true )."</p>";
希望这会有所帮助!