我正在寻找等效于使用 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/