Auto Populate Custom Field – Please Help!!!
-
Hi guys,
I need help to solve this.
Please read my original post:
https://wordpress.stackexchange.com/questions/107127/auto-populate-custom-field-with-complex-value-that-increase-by-oneSo… I have this code:
add_action( 'save_post', 'setOrderNumber'); function setOrderNumber($post_id) { $slug = 'orders'; // slug of your post_type called "Orders" if ( $slug != $_POST['post_type'] ) { return; } if ( !current_user_can( 'edit_post', $post_id ) ) { return; } $counter = get_option( 'lastOrderCount' ); // example 0051 $counter++; // returns 0052 update_post_meta($post_id, 'purchase_order', 'POCOS'.date('Y').$counter); update_option( 'lastOrderCount', $counter ); // set the new number of order. }
…but this $counter does not work because 4 character number is missing at the end of the record. Check this image: https://img32.imageshack.us/img32/7595/l76c.jpg
Also, I need to secure this field not to change value if value already exist. That is important if somebody want to edit post. I think that I need something like “IF NOT NULL DO NOTHING”, but if you think that this can be solved another way, I will be satisfied with your solution.
- The topic ‘Auto Populate Custom Field – Please Help!!!’ is closed to new replies.