你传递的args get_posts 正在呼唤 10 帖子,所以你永远不会在回复中得到更多。
get_posts
10
'numberposts' => 10,
但是,如果您希望显示条件恰好为10:
if (count($attachments) === 10) { // proceed }
您拥有的代码最多只能获得10个帖子, 'numberposts' => 10, 。要检索您可以使用的所有附件 'numberposts' => -1, 。参考 https://developer.wordpress.org/reference/functions/get_posts/ 。
'numberposts' => -1,
然后你可以检查是否至少有10个附件:
if (count($attachments) >= 10) { // display widget }
这是你的追求吗?
if (count($attachments) > 10) { // code here }
get_posts()返回一个帖子数组,因此您只需计算它返回的数组中的元素数。