Not adding a new post?


I am trying to add a new post via the front form. This is how it looks:
I insert the form in the right place via get_template_part, here is the form itself:

    <form class="consult__form-q" id="consultations-form" action="" method="post">
    <label>Задать вопрос</label>
    <input name="name" type="text" placeholder="Ваше имя" required>
    <input name="mail" type="text" placeholder="Email" required>
    <input name="theme" type="text" placeholder="Тема" required>
    <textarea name="text"  placeholder="Задайте свой вопрос тут" required></textarea>

    <button type="submit">Задать вопрос</button>
    <input type="hidden" name="submitted" id="submitted">
<?php submit_consultations_form() ?>

Here is the handler function itself, I put it in function.php, I checked it for sure:

    function submit_consultations_form()
    if (isset($_POST['submitted'])) {

        $post_data = array(
            'post_title'    => wp_strip_all_tags($_POST['theme']),
            'post_content'  => wp_strip_all_tags($_POST['text']),
            'post_author'   => wp_strip_all_tags($_POST['name']),
            'post_type'      => 'questions',

        $post_id = wp_insert_post( wp_slash($post_data) );



The problem is that the new post is simply not being added. What am I doing wrong?

dg g4re 8 months 2020-11-25T07:10:35-05:00 0 Answers 11 views 0

Leave an answer