I'd like to query post revisions using WP_Query
for display on an admin page, and I want to include pagination parameters.
I have two constraints:
I would like to only retrieve revisions for published posts, i.e. revisions whose parent - the post ID for which is given in the
post_parent
field - containspublish
in itspost_status
field.I would like to ignore the revision autogenerated when a post is published, i.e. the revision whose
post_date
matches that of the parent.
Normally I would simply filter these revisions out after getting the array of posts, but I want to display these elements in an admin list table with pagination so I'd like to use WP_Query
's support for that.
In SQL, I would use an INNER JOIN like this to grab the parent posts:
SELECT * FROM {$wpdb->posts} AS posts
INNER JOIN {$wpdb->posts} AS parent_posts
ON posts.post_parent = parent_posts.ID
WHERE posts.post_type = 'revision'
AND parent_posts.post_status = 'publish'
AND posts.post_date <> parent_posts.post_date
Is this possible to do this using WP_Query
?