Skip to content

Instantly share code, notes, and snippets.

@wgroenewold
Created February 24, 2016 16:13
Show Gist options
  • Save wgroenewold/a8adf6e2f238f0aafd7c to your computer and use it in GitHub Desktop.
Save wgroenewold/a8adf6e2f238f0aafd7c to your computer and use it in GitHub Desktop.
function updateIndexNumbers($postid) {
$post = get_post($postid);
if ($post->post_type == 'project') {
$args = array(
'post_type' => 'project',
'posts_per_page' => -1,
'post_status' => 'publish',
'order' => 'ASC',
'orderby' => 'date'
);
$posts = get_posts($args);
$count = 0;
if ($posts) {
foreach ($posts as $value) {
$count++;
add_post_meta($value->ID, 'incr_number', $count, true);
update_post_meta($value->ID, 'incr_number', $count);
}
}
}
}
add_action ( 'publish_post', 'updateIndexNumbers', 11 );
add_action ( 'deleted_post', 'updateIndexNumbers' );
add_action ( 'edit_post', 'updateIndexNumbers' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment