• Resolved Amid

    (@aminteractiondesign)


    Hi everybody, I need to display the current id of a post and the total number of posts of a custom post type in a single view, like

    3 / 18

    Now i managed to get the total number (18 in this case) like this: wp_count_posts(‘portfolio’);

    But how do i get the Number of the current post?
    get_the_ID() returns the id considering all post types, so this is spitting out something like 80 :-/

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Are you doing this within a loop?

    Inside the loop you already have a $post object available.

    <?php echo $post->post_type; ?>

    Or if you want to use get_post_type you can pass it the post object you have (so it extracts the one property from it).

    <?php echo get_post_type( $post ); ?>

    Thread Starter Amid

    (@aminteractiondesign)

    Got a solution for this on the german forums:

    <?php
    if ( 'portfolio' == get_post_type() ) {
    	$this_post_id = get_the_id();
    
    	$args = array(
    		'post_type' => 'portfolio',
    		'post_status' => 'publish',
    		'posts_per_page' => -1,
    		'fields' => 'ids',
    		'order' => 'ASC',
    	);
    	$the_query = get_posts( $args );
    
    	$key = array_search( $this_post_id , $the_query );
    	$key++;
    
    	$published_posts = wp_count_posts( 'portfolio' )->publish;
    
    	echo ' ' . $key . ' / '. $published_posts;
    }	//end if post type ?>
    Thread Starter Amid

    (@aminteractiondesign)

    resolved ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘get the id of one custom post type item for nav’ is closed to new replies.