Last active
November 9, 2016 22:00
-
-
Save tripflex/1709c7f30ec3819f275518d04f836a7a to your computer and use it in GitHub Desktop.
Create/Add an auto incrementing field whenever a new Job Listing is posted (for WP Job Manager)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'job_manager_update_job_data', 'smyles_add_auto_increment_field', 10, 2); | |
function smyles_add_auto_increment_field( $job_id, $values ){ | |
$meta_key = '_my_increment_field'; | |
$inc_option = 'smyles_job_auto_increment'; | |
$already_set = get_post_meta( $job_id, $meta_key, true); | |
$last_num = get_option( $inc_option, 0 ); | |
if( ! $already_set ){ | |
$next_num = (int) $last_num + 1; | |
update_post_meta( $job_id, $meta_key, $next_num ); | |
update_option( $inc_option, $next_num ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment