0
add_filter( 'wpcf7_posted_data', 'save_posted_data', $priority = 10, $accepted_args = 1 );
function save_posted_data( $posted_data ) {
    if ($posted_data->id() == [290]) {
        $args = array(
            'post_type' => 'reviews',
            'post_status'=>'draft',
            'post_title'=>$posted_data['your-name'],
            'post_content'=>$posted_data['your-message'],
        );
        $post_id = wp_insert_post($args);

        if(!is_wp_error($post_id)){
            if( isset($posted_data['your-name']) ){
                update_post_meta($post_id, 'your-name', $posted_data['your-name']);
            }
            // if( isset($posted_data['your-email']) ){
            //   update_post_meta($post_id, 'your-email', $posted_data['your-email']);
            // }
            // if( isset($posted_data['your-subject']) ){
            //   update_post_meta($post_id, 'your-subject', $posted_data['your-subject']);
            // }
            if( isset($posted_data['your-message']) ){
                update_post_meta($post_id, 'your-message', $posted_data['your-message']);
            }
            //and so on ...
            return $posted_data;
        }
    }
}

Сейчас при проверки так if ($posted_data->id() == [290]) { форма не отправляется.

4
  • А что выведет var_dump( $posted_data->id() ) в самом начале функции? 14 фев 2019 в 15:35
  • Ничего, форма не отправляется, постоянно крутится prntscr.com/ml3p46
    – Makissm
    14 фев 2019 в 15:37
  • Ну в лог файл выведите. Надо узнать значение переменной. 14 фев 2019 в 15:41
  • В логе с ошибками пишет PHP Fatal error: Call to a member function id() on array
    – Makissm
    14 фев 2019 в 15:52

1 ответ 1

0

Нашел решение, получить id формы Contact form 7 можно так

$form_id = WPCF7_ContactForm::get_current();
if ($form_id->id == 290) {

}

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.