获取 Wordpress 中的所有帖子 ID [英] Get all post IDs in Wordpress

查看:33
本文介绍了获取 Wordpress 中的所有帖子 ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以获取当前存在于 wordpress 数据库中的所有帖子 ID 的数组(不考虑 post_types)?另外,是否可以获取特定 post_type 的所有帖子 ID 的数组?

Is it possible to get an array of all post IDs currently present in the wordpress DB (irrespective of post_types)? Also, is it possible to get an array of all post IDs of a specific post_type?

如果可以,如何实现?

推荐答案

你可以试试这个方法

    $post_ids = get_posts(array(
        $args, //Your arguments
        'posts_per_page'=> -1,
        'fields'        => 'ids', // Only get post IDs
    ));

这篇关于获取 Wordpress 中的所有帖子 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆