使用此脚本,我的特殊自定义字段“昵称”仅计算一次,如果这些字段在帖子中可用两次或更多次。
有没有办法计算帖子中名为“昵称”的所有特殊自定义字段?
这是剧本:
<?php
$posts_with_nickname = get_posts(array(
'category__in' => array(2,5),
'meta_key' => 'Nickname',
'showposts' => -1,
));
printf('I have %d posts with "Nickname"!', count($posts_with_nickname));
?>
答案 0 :(得分:0)
您可能想要使用meta_query
<?php
$posts_with_nickname = get_posts(
'category__in' => array(2,5),
'meta_query' => array(
array(
'key' => 'Nickname',
'value' => '',
'compare' => 'NOT LIKE',
),
),
'showposts' => -1,
);
printf('I have %d posts with "Nickname"!', count($posts_with_nickname));