posts WHERE post_status =-6ren">
gpt4 book ai didi

php - 特定类别的用户帖子计数 [Wordpress]

转载 作者:行者123 更新时间:2023-11-29 15:02:59 25 4
gpt4 key购买 nike

我想显示特定类别的用户帖子计数。目前,我只能查询所有帖子。我的代码是这样的

<?php $userpost_count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type ='post' AND post_author = '".$curauth->ID."'");?>
<?php echo "<span>Total post: </b></span>".$userpost_count.""?>

我知道,我需要连接两个表,即 post 表和 term_relationships,但我不知道如何获取它。请帮助我。谢谢。

最佳答案

使用下面的 CATEGORY_ID 并尝试此操作:

<?php $userpost_count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts
LEFT JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id)
LEFT JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
WHERE $wpdb->term_taxonomy.term_id = CATEGORY_ID
AND $wpdb->term_taxonomy.taxonomy = 'category'
AND $wpdb->posts.post_status = 'publish'
AND post_author = '".$curauth->ID."'");?>

关于php - 特定类别的用户帖子计数 [Wordpress],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2712908/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com