在WordPress中获取10天之内的文章更新数

要在WordPress中获取10天之内的文章更新数,您可以使用以下代码片段。这段代码将显示在过去10天内更新的文章数量。

复制代码
<?php
// 获取当前时间戳
$now = time();

// 计算10天前的时间戳
$ten_days_ago = $now - (10 * 24 * 60 * 60);

// 设置查询参数
$args = array(
    'post_type' => 'post', // 只查询文章类型的帖子
    'post_status' => 'publish', // 只查询已发布的帖子
    'posts_per_page' => -1, // 查询所有结果
    'orderby' => 'post_modified', // 按修改时间排序
    'order' => 'DESC', // 降序排列
    'date_query' => array( // 添加日期查询条件
        array(
            'after' => date('Y-m-d H:i:s', $ten_days_ago), // 只查询10天后的数据
        ),
    ),
);

// 执行查询
$query = new WP_Query($args);

// 获取查询结果的数量
$updated_posts_count = $query->found_posts;

// 显示结果
echo '过去10天内更新的文章数量:' . $updated_posts_count;
?>

将此代码添加到您的WordPress主题中的functions.php文件或自定义插件中,即可在网站上显示过去10天内更新的文章数量。

原文

https://www.jianzhanpress.com/?p=7072

相关推荐
张太行_1 天前
Linux静态库:多模块高效管理
linux·运维·服务器
wgl6665201 天前
Linux---基础IO!
linux·运维·服务器
Ancelin安心1 天前
kali-dirsearch的使用
linux·运维·服务器·python·计算机网络·web安全·网络安全
jun_bai1 天前
python+Java的网盘程序升级版。无感知备份文档,保护数据资产利器。
运维·服务器
suzhou_speeder1 天前
PoE 延长器:突破 PoE 距离限制,优化网络灵活部署方案
运维·网络·poe·poe交换机·poe延长器
月光下的麦克1 天前
如何查案动态库版本
linux·运维·c++
EndingCoder1 天前
索引类型和 keyof 操作符
linux·运维·前端·javascript·ubuntu·typescript
liux35281 天前
Web集群管理实战指南:从架构到运维
运维·前端·架构
石小千1 天前
Linux清除缓存
linux·运维
weixin_516023071 天前
VESTA在Linux下的安装
linux·运维·服务器