Tell us what you are trying to do? Add a permit number field that auto generates and auto increments for each permit (i.e. permit 1, permit 2, etc.)
Is there any documentation that you are following? I have been following your support posts at:
https://toolset.com/forums/topic/auto-numbering-posts/
https://toolset.com/forums/topic/disable-cpt-auto-numbering-when-editing-post/
Both of which were helpful. However, I can see an autogenerated number in the permit number field but it's always 1 in every permit. The code I'm using is as follows:
/* Auto number Permits */
add_action( 'save_post', 'auto_number', 100, 3 );
function auto_number( $post_id, $post, $update ) {
if ( $post->post_status == 'publish' && $post->post_type == 'permit' ) {
$project_args = array(
'numberposts' => 2,
'post_type' => 'permit',
'orderby' => 'post_date',
'order' => 'DESC'
);
$projects = get_posts( $permit_args );
// don't update existing auto-numbering
$this_id = get_post_meta( $permit[0]->ID, 'wpcf-permitnumber', true);
if ( $this_id ) {
return;
}
$last_id = get_post_meta( $permit[1]->ID, 'wpcf-permitnumber', true);
if ( !$last_id ) {
$last_id = 0;
}
$last_id++;
update_post_meta( $post_id, 'wpcf-permitnumber', $last_id );
}
}
permit is the post type and wpcf-permitnumber is the custom field.
The permits are being created with a front end post form.
Is there a similar example that we can see? Only in those posts.
What is the link to your site? hidden link
Any help much appreciated!
Kind regards
James