• I’m trying to get the current user post count ( custom post type ‘tourism’ )

    // Add Shortcode
    function total_post_count() {
    
    	$current_user = wp_get_current_user();
    	if ( 0 == $current_user->ID ) {
    	    // Not logged in.
    	} else {
    	    echo count_user_posts( $current_user->ID );
    	}
    
    }
    add_shortcode( 'total_post_c', 'total_post_count' );

    how can I specify the custom post type. I also tried
    echo count_user_posts( $current_user->ID, ‘tourism’ );
    please give me the solution

    • This topic was modified 4 years ago by bcworkz.
Viewing 1 replies (of 1 total)
  • you can try

    $args = array(
        'post_type' => 'tourism',
        'post_author' => $current_user->ID,    
    );
    $query = new WP_Query( $args );
    $count = count( $query->get_posts() );
    • This reply was modified 4 years ago by bcworkz.
Viewing 1 replies (of 1 total)
  • The topic ‘Get current user post count ( custom post type ‘tourism’)’ is closed to new replies.