Answer the question
In order to leave comments, you need to log in
WordPress. How to find out the id of a post before publishing?
How can I find out the id of a post of an arbitrary type that has not yet been published or saved, or, more simply, a post of an arbitrary type that is currently being created
Answer the question
In order to leave comments, you need to log in
What do you mean "arbitrary type"? Post is type "post" or not o_O? Post of arbitrary type, is it like "cold boiling water", or something like that?
And before saving, you can try to display the post id in a similar way:
global $post;
$post_type = $post->post_type;
if ($post_type == 'auto-draft') {
$post_id = $post->ID;
echo $post_id;
}
Well, it will also add a check to display only the ID of the current post.
But here it is important to understand that you won’t display it so easily, firstly you need to do it through js, without reloading the page (because if with a reload, then this is either resetting the post or saving, if saving, then there is an ID and so on) , secondly, it should be displayed after the page/post autosave event has fired, and after this event is fired, display the ID you need on the current page via JS. But it is not exactly.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question