【问题标题】:Wordpress: echo TOTAL amount of posts for post author by meta_key?Wordpress:通过 meta_key 回显帖子作者的帖子总数?
【发布时间】:2021-07-07 21:37:03
【问题描述】:

好的,所以我知道如何回显帖子的 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() 以仅显示帖子作者的帖子总数,但现在挣扎了一段时间。

任何帮助将不胜感激。

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    在 WP_Query() 中使用 Author Parameters。您可以使用作者 ID/姓名/多位作者。对于您的情况,查询应如下所示:

    <?php
    $query = new WP_Query(
        array(
            'author' => get_the_author_meta( 'ID' );
            'meta_key' => '_heart_this',
        ),
     );
    echo $query->found_posts; ?>
    

    【讨论】:

      猜你喜欢
      • 2017-06-30
      • 2023-03-09
      • 1970-01-01
      • 1970-01-01
      • 2012-02-08
      • 1970-01-01
      • 2012-12-10
      • 1970-01-01
      • 2017-04-23
      相关资源
      最近更新 更多