Last active
September 29, 2015 08:40
-
-
Save marushu/2e59d6271da47df9f47b to your computer and use it in GitHub Desktop.
投稿ナンバリング
This file contains 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
<?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