Skip to content

Instantly share code, notes, and snippets.

@oknoway
Created October 7, 2013 15:55
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 oknoway/6870252 to your computer and use it in GitHub Desktop.
Save oknoway/6870252 to your computer and use it in GitHub Desktop.
function number_expeditions( $post_ID ) {
global $wpdb;
if ( !wp_is_post_revision( $post_ID ) ) {
$dispatchNumber = false;
$parent = wp_get_post_parent_id( $post_ID );
$dispatchArgs = array(
'numberposts' => -1,
'order' => 'ASC',
'orderby' => 'date',
'post_parent' => $parent,
'post_status' => 'publish',
'post_type' => 'nse_expedition',
);
$dispatches = get_children( $dispatchArgs );
if ( !array_key_exists( $post_ID , $dispatches ) ) :
$dispatchNumber = count( $dispatches ) + 1;
else:
$i = 1;
foreach ( $dispatches as $c => $dispatch ) :
if ( $c == $post_ID ) :
$dispatchNumber = $i;
endif;
$i++;
endforeach;
endif;
if ( $dispatchNumber )
add_post_meta($post_ID, 'nse_dispatch_number', $dispatchNumber, true);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment