php - Wordpress:通过 meta_key 回显帖子作者的帖子总数?
问题描述
好的,所以我知道如何回显帖子的 meta_key 值:
<?php
$meta_print_value=get_post_meta(get_the_ID(),'_heart_this',true);
echo($meta_print_value);
?>
我也知道如何用这个特定的 meta_key 回显所有帖子:
<?php $query = new WP_Query( array( 'meta_key' => '_heart_this' ) )
echo $query->found_posts; ?>
我需要的是帖子作者的这个 meta_key 的帖子总数。
我知道我需要get_the_author()
在上面的代码中添加某处以仅显示帖子作者的帖子总数,但现在挣扎了一段时间。
任何帮助,将不胜感激。
解决方案
在 WP_Query() 中使用作者参数。您可以使用作者 ID/姓名/多位作者。对于您的情况,查询应如下所示:
<?php
$query = new WP_Query(
array(
'author' => get_the_author_meta( 'ID' );
'meta_key' => '_heart_this',
),
);
echo $query->found_posts; ?>
推荐阅读
- ionic-framework - 在 Cypress 中,当默认滚动元素不可滚动时,如何使用 scrollIntoview() 函数?
- audio - Gstreamer 将音频延迟应用于实时流
- python - 函数添加不需要的行
- c# - 如何用文本填充 DataGridView?
- html - Blazor 上的 Svg 图像显示本地主机上的加载缓慢
- python - 如何跳过没有内容的值?
- r - Subtract one hour from hms in R without generating negative values
- mysql - 如何查询属于另一个表中 2 个不同值的实体?
- python - 如何定义多种用途的字典?
- mysql - 从表限制中查找员工参加会议的次数