I have custom post type works with custom taxonomy work_category I want to build such pagination while viewing single.php

previous 2/25 next

[link to previous post in custom tax] [current post number]/[all post number from custom tax] [next post in custom tax]

Currently i can't get current post number

1 Answer 1


I've solved it

For previous/next use Ambrosite Next/Previous Post Link Plus

To get current/all use following code inside the loop

        $query = new WP_Query( array(
            'post_type' => 'works',
            'post_status' => 'publish',
            'posts_per_page' => '-1',
            'tax_query' => array(
                        'taxonomy' => 'work_category',
                        'field' => 'slug',
                        'terms' => 'design'
            'order' => 'ASC'
        ) );
        $all = $query->post_count;
        foreach( $query->posts as $key => $p )
            if( $post->ID == $p->ID ) $current = $key + 1;

        echo $current.'/'.$all;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.