Inserção de post (ou custom post) via frontend
<?php
if ( isset( $_POST['submitted'] ) && isset( $_POST['post_nonce_field'] ) && wp_verify_nonce( $_POST['post_nonce_field'], 'post_nonce' ) ) {
$postTitleError = '';
if ( isset( $_POST['submitted'] ) ) {
if ( trim( $_POST['postTitle'] ) === '' ) {
$postTitleError = 'Please enter a title.';
$hasError = true;
}
}
global $wpdb;
$user_id = get_current_user_id();
$areas = $_POST['area'];
$post_information = array(
'post_title' => wp_strip_all_tags( $_POST['postTitle'] ),
'post_content' => $_POST['postContent'],
'post_type' => 'projetos',
'post_status' => 'publish'
);
//wp_insert_post( $post_information );
$post_id = wp_insert_post($post_information);
$descricao_do_problema = $_POST['descricao_do_problema'];
add_post_meta($post_id, 'descricao_do_problema', $descricao_do_problema, true);
$bool_formacao_especifica = $_POST['formacao_especifica'];
add_post_meta($post_id, 'formacao_especifica', $bool_formacao_especifica, true);
$qual_formacao = $_POST['qual_formacao'];
add_post_meta($post_id, 'qual_formacao', $qual_formacao, true);
$outra_formacao = $_POST['outra_formacao'];
add_post_meta($post_id, 'outra_formacao', $outra_formacao, true);
wp_set_object_terms( $post_id, $areas, 'area' );
}
?>