Skip to content

Instantly share code, notes, and snippets.

@marushu
Last active September 29, 2015 08:40
Show Gist options
  • Save marushu/2e59d6271da47df9f47b to your computer and use it in GitHub Desktop.
Save marushu/2e59d6271da47df9f47b to your computer and use it in GitHub Desktop.
投稿ナンバリング
<?php
function sequential_posts_numberting( $post_type = 'post', $posts_per_page = -1, $post_status = 'publish' ) {
$posts_keys = array();
$args = array(
'post_type' => $post_type,
'posts_per_page' => $posts_per_page,
'post_status' => $post_status,
);
$sequential_posts = get_posts( $args );
if( ! empty( $sequential_posts ) ) {
foreach( $sequential_posts as $key => $sequential_post ) {
$posts_keys[$key] = $sequential_post->ID;
}
}
$post_id = get_the_ID();
$post_position = array_search( $post_id, array_reverse( $posts_keys ) );
$post_position += 1;
return intval( $post_position );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment