there is a major problems in your code :
1- you must use the <form>
when you want to submit the data whatever the system you use (wordpress, EE ,php ,html …).
2- if you want to check if the page submitted or just visited without submitted, you must change your condition to :
if(!empty($_POST)){
OR
if($_POST){
3- if you try to avoid the resend the Post data when you refresh the page after the submit process , you must add redirect code inside your condition.
4- move this $thisid = wp_insert_post ( $post, true);
inside the condition ,so the post will be added just if there is a $_post data and remove wp_insert_post($thisid);
from else statement.
4- about add_post_meta
in your code you use wp_insert_post , so your code to add a new post then add a new meta to this post, so if you go to the new post and find the meta field this tell you add_post_meta
is working.
note: you can add the same line twice to see if add_post_meta
add two meta fields.
add_post_meta( $thisid, 'field_123123eee12312', $column2);
add_post_meta( $thisid, 'field_123123eee12312', $column2);
so you code will look something like this:
<form action="" method="post">
--- Your Fields -----
<input type="submit" value="Test" id="submit">
</form>
———-PHP Code———
if(!empty($_POST)){
$thisid = wp_insert_post ( $post, true);
if ( is_wp_error($thisid) ) {
return get_error_codes();
echo "not ok";
}else{
add_post_meta( $thisid, 'field_123123eee12312', $column2);
echo "ok";
}
}
try it and let me know.
Regard’s.