I’m inserting custom post type with following code:
if(isset($_POST['submit'])){
$post_id = wp_insert_post( array(
'post_status' => 'publish',
'post_type' => 'custom_type',
'post_title' => 'Some post',
'post_content' => 'Lorem ipsum'
) );
}
and I’m getting error page with; Title: “WordPress failure notice” and text in page “Are you sure you want to do this?
Please try again.”
But when I try to insert post_type: post then is everything ok.
And everything is ok when i try to insert without isset;
$post_id = wp_insert_post( array(
'post_status' => 'publish',
'post_type' => 'custom_type',
'post_title' => 'Some post',
'post_content' => 'Lorem ipsum'
) );
Anybody had same problem?
I have not found solution except this (AND IT WORKS):
Had the same problem with inserting new custom post type. Found the temporary solution by unseting the $_POST before calling wp_insert_post function.
I got mine to work with this:
PHP, placed before the header:
and in the HTML:
Try this out this is the form header
The if statement I make is this