rest api - How do I get the intended post type of a revision post?

I have a headless Wordpress instance with multiple custom post types. The build takes a few minutes, so I'm buildin

I have a headless Wordpress instance with multiple custom post types. The build takes a few minutes, so I'm building a way to display drafts by fetching the latest revision via an API, like so:

$revision = wp_get_post_revision($id);
wp_send_json($revision);

I retrieve the revision just fine, but the post type is set to revision instead of my custom post type. This causes problems, because I need the intended post type in order to build up a valid response that I can parse on the front-end.

How can I obtain the intended post type of a revision post?

I have a headless Wordpress instance with multiple custom post types. The build takes a few minutes, so I'm building a way to display drafts by fetching the latest revision via an API, like so:

$revision = wp_get_post_revision($id);
wp_send_json($revision);

I retrieve the revision just fine, but the post type is set to revision instead of my custom post type. This causes problems, because I need the intended post type in order to build up a valid response that I can parse on the front-end.

How can I obtain the intended post type of a revision post?

Share Improve this question asked Sep 26, 2019 at 12:02 maxmax 1211 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 2

Post revisions have the original post as their parent, so you can get the post type by checking the post type of the revision's parent:

$revision  = wp_get_post_revision( $id );
$post_type = get_post_type( $revision->post_parent );

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745127061a4612751.html

相关推荐

  • rest api - How do I get the intended post type of a revision post?

    I have a headless Wordpress instance with multiple custom post types. The build takes a few minutes, so I'm buildin

    10小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信