Created
February 24, 2016 16:13
-
-
Save wgroenewold/a8adf6e2f238f0aafd7c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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