Create/Add an auto incrementing field whenever a new Job Listing is posted (for WP Job Manager)

functions.php

<?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 );
	}

}
No comments yet.

Leave a Reply