Wordpress loop - how to count items

后端 未结 3 1802
孤城傲影
孤城傲影 2021-01-07 19:56

Is there a way to get a number of items within Wordpress loop code:


This loop lists the p

3条回答
  •  醉梦人生
    2021-01-07 20:41

    You can use the post_count property of $WP_Query, like so:

    $wp_query->post_count
    

    Be aware of the difference with found_posts, which counts the posts which, though matching the query, are not being displayed (e.g. for pagination). You might want to use one or the other depending on your particular situation.

提交回复
热议问题