Post count for custom post retutns 0
-
i am trying to get the number of posts (for a custom post type) by author, first I used
count_user_posts($userID , 'recipe')
then i trried the work around :function nbrPostByUser( $userid, $post_type = ['recipe'] ) { global $wpdb; $where = get_posts_by_author_sql( $post_type, true, $userid ); $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts $where" ); return apply_filters( 'get_usernumposts', $count, $userid ); }
it always returns 0 …. after debugging I think that the cause is that my custom post type is not included in the global $wp_post_types.
are my approaches correct ? if yes what went wrong then?
Thanks
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Post count for custom post retutns 0’ is closed to new replies.