Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Placed in functions.php
- <?php
- function Get_Post_Number($postID){
- $temp_query = $wp_query;
- $postNumberQuery = new WP_Query('orderby=date&order=ASC&category_name=episodes&posts_per_page=-1');
- $counter = 1;
- $postCount = 0;
- if($postNumberQuery->have_posts()) :
- while ($postNumberQuery->have_posts()) : $postNumberQuery->the_post();
- if ($postID == get_the_ID()){
- $postCount = $counter;
- } else {
- $counter++;
- }
- endwhile; endif;
- wp_reset_query();
- $wp_query = $temp_query;
- return $postCount;
- }
- ?>
- //Used to call function in template
- <?php $currentID = get_the_ID(); ?>
- <?php $currentNumber = Get_Post_Number($currentID); ?>
- <?php echo $currentNumber; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement