Skip Navigation

[Resolved] Autoincrement issue

This support ticket is created 3 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 6 replies, has 2 voices.

Last updated by Minesh 3 years, 5 months ago.

Assisted by: Minesh.

Author
Posts
#2070229

https://toolset.com/forums/topic/disable-cpt-auto-numbering-when-editing-post/

Hello, I was following this topic about autoincrement custom field, I was able to customize it and make it work but there is only one problem, it does not work when I add a new post from the parent post editor.

Suppose I have two related custom types: A, B

If I create an A post, and inside the A post editor I create a related post B, the autoincrement custom field does not work, I need to go to post B editor page to update in order to autoincrement the custom field value.

#2070763

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Toolset offers the post relationship API hook "toolset_association_created" - can you please try to add same code within this hook and adjust the code accordingly and see if that helps you to resolve your issue:
=> https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_association_created

#2071191

Thank you I'll try this solution, but can you explain me why creating posts on relationship tab does not trigger the "save_post" hook?

#2071321

I think this hook does not work for me because I need to retrieve the post_type of the newly created post. This hook does not provide the newly created post_id but it provides both parent_id and child_id so I can't know which one is the newly created. It works only if I go through both parent post and child post.

#2072181

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

To check why the hook you shared is not working I'll require admin access details and to what post type you want to apply the hook.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2076467

Can you confirm me whether creating posts on relationship metabox triggers the "save_post" hook please? Thanks

#2079159

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I've one to many relationship created between post type student and student-reviews.

I've added the following save_post hook for student-review. When I try to create a new student review from post-relationship box when editing a single student from backend, when I try to create new student review, I can see that the following hook is called.

add_action( 'save_post', 'auto_number', 100, 3 );
function auto_number( $post_id, $post, $update ) {
    if ( $post->post_status == 'publish' && $post->post_type == 'student-review' ) {
			echo "<pre>";
			print_r($_POST);
			exit;
     
    }
}