本文作者:StubbornHuang
版权声明:本文为站长原创文章,如果转载请注明原文链接!
原文标题:WordPress – 获取某个用户发表的文章数量
原文链接:https://www.stubbornhuang.com/1363/
发布于:2021年05月26日 15:11:53
修改于:2021年05月26日 15:11:53
1 官方函数
<?php $user_post_count = count_user_posts( $userid , $post_type ); ?>
函数参数:
- $userid : 用户的ID,必填项
- $post_type : 文章类型,默认为 post,选填
2 使用sql函数查询
function num_of_author_posts( $user_id ){
global $wpdb;
$user_id = (int) $user_id;
$sql = "SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_author='$user_id' AND post_status = 'publish' ";
$coo = $wpdb->get_var( $sql );
return ( $coo ) ? $coo: 0;
}
当前分类随机文章推荐
- WordPress - 在用户登录页面添加自定义提示信息 阅读1607次,点赞0次
- WordPress - PhpStudy本地环境修改固定链接打不开网页404错误 阅读4513次,点赞1次
- WordPress - 添加网页三角网粒子背景 Canvas-nest.js 阅读3497次,点赞0次
- WordPress - count_user_posts函数,获取某个用户发表的文章数量 阅读813次,点赞0次
- WordPress - get_footer函数,加载主题底部页脚footer模板 阅读842次,点赞0次
- WordPress - home_url()函数,获取网站主页url链接 阅读886次,点赞0次
- WordPress - 异步发送邮件,解决发送邮件阻塞耗时的问题 阅读62次,点赞0次
- WordPress - 在每一个文章内容末尾都加一个作者信息展示框 阅读2132次,点赞0次
- WordPress - 在编辑文章发布时弹出是否发布提醒框 阅读3300次,点赞0次
- WordPress - WordPress后台登录设置验证码,防止恶意爆破网站 阅读3909次,点赞0次
全站随机文章推荐
- Pytorch - 没有使用with torch.no_grad()造成测试网络时显存爆炸的问题 阅读554次,点赞0次
- 资源分享 - Introduction to Computer Graphics - A Practical Learning Approach 英文高清PDF下载 阅读1122次,点赞0次
- OpenCV - Mat与lplImage和CvMat的相互转换 阅读3736次,点赞0次
- C++ - 使用C++标准库过滤Windows文件名中的非法字符 阅读4566次,点赞1次
- 资源分享 - GPU Pro 7 - Advanced Rendering Techniques 英文高清PDF下载 阅读2586次,点赞0次
- C++11 - std::string - stod/stof/stoi/stol/stold/stoll/stoul/stoull,由std::string转换为int/long/float/double等其他类型 阅读3517次,点赞0次
- WordPress - 升级WordPress5.8后切换回旧版的小工具管理页面 阅读1587次,点赞0次
- Python - 使用with open as 读写文件 阅读1566次,点赞0次
- 资源分享 - Artificial Intelligence for Games , Third Edition 英文高清PDF下载 阅读677次,点赞0次
- C++ - std::map正向遍历与反向遍历的几种方式 阅读4447次,点赞3次
评论
169