php - Wordpress 查询预览?

标签 php wordpress

我正在寻找等效于使用 WP 查询或 get_posts 获取页面/帖子的方法,例如:

$args=array(                        
  'category' => 1,
  'name' => 'my-page',
  'post_type' => 'page',
  'post_status' => 'publish',
  'numberposts' => 1
);
$my_post = get_posts($args);

但我想预览一下,我只有预览 GET 参数:

?preview=true&preview_id=5&preview_nonce=b0d41a7fdb

preview_id 实际上是创建的帖子的 ID,而不是预览的 ID。

有什么想法吗?

最佳答案

所以我最终找到了一个可能的答案 - 这应该检索最新的预览或“修订版”:

$args = array(
  'post_status' => 'any',
  'post_parent' => intval($_GET['preview_id']),
  'post_type' => 'revision',
  'sort_column' => 'ID',
  'sort_order' => 'desc',
  'posts_per_page' => 1
);
$my_post = get_posts($args);

关于php - Wordpress 查询预览?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21544161/

相关文章:

php - 时区和保存的时间戳

php - Ajax 发布带有数字但不带有字母的字符串

其他语言的 WordPress

php - WordPress 数据库数组不传递数据

php - 我正在尝试在Win7机器上使用php 5.3.5从ubuntu服务器检索文件

javascript - 将 php 数组从 php 文件引入 js 文件中的 javascript 数组

php - 如何在一个查询中更新来自不同表的两条记录?

javascript - 为什么这个 Javascript 文件停止工作(在 WordPress 中)?

php - Wordpress 自定义帖子分页 404 错误

php - 仅当强制类别的产品在购物车中时才允许结帐