How to count current user’s pages?

Look what count_user_posts() does inside and change the post type parameter:

global $wpdb;
// 'page' is the important part here
$where = get_posts_by_author_sql('page', true, $userid);
$count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts $where" );

Then you change your snippet to:

global $wpdb;
$user = wp_get_current_user();
$where = get_posts_by_author_sql( 'page', true, $user->ID );
$count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts $where" );

if ( $count >= 1 ) {

    // echo your text snippet

} else {

    // echo your form

}

Leave a Comment