Skip to content

Instantly share code, notes, and snippets.

@tripflex
Last active November 9, 2016 22:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tripflex/1709c7f30ec3819f275518d04f836a7a to your computer and use it in GitHub Desktop.
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)
<?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