前端提交未过帐到自定义发布类型

时间:2013-11-18 作者:Mike Jr.

我有一个自定义脚本,允许添加每个表单提交,以将联系人添加到自定义帖子类型。但出于某种原因,它总是将数据添加到帖子中,而不是添加到帖子类型中。

到目前为止,我已经尝试了所有的方法,但没有找到我取出的表单的代码,因为该部分工作正常

        if( !isset( $hasError ) ) {

        $submit_to_contact_manager = array(
            \'post_title\' => \'Request from \'. esc_attr(strip_tags($_POST[\'request_lastname\'])),
            \'post-type\' => \'tpf_cnm\',
            \'post_status\' => \'pending\'
        );

        $contactmanager_id = wp_insert_post($submit_to_contact_manager);

        if($contactmanager_id)
        {

            // Update Custom Meta
            update_post_meta($contactmanager_id, \'tpf_first_name_preorders\', esc_attr(strip_tags($_POST[\'request_firstname\'])));
            update_post_meta($contactmanager_id, \'tpf_last_name_preorders\', esc_attr(strip_tags($_POST[\'request_lastname\'])));
            update_post_meta($contactmanager_id, \'tpf_email_preorders\', esc_attr(strip_tags($_POST[\'request_email\'])));
            update_post_meta($contactmanager_id, \'tpf_preorder_desc\', esc_attr(strip_tags($_POST[\'request_message\'])));
            update_post_meta($contactmanager_id, \'tpf_preorder_desc\', esc_attr(strip_tags($_POST[\'request_category\'])));


        }
    }
这里是post-type函数

        add_action(\'init\', \'tpf_cnm_init\');

    function tpf_cnm_init(){

    $tpf_cnm_type_labels = array(
    \'name\' => _x(\'Contacts\', \'post type general name\'),
    \'singular_name\' => _x(\'Contact\', \'post type singular name\'),
    \'add_new\' => _x(\'Add New Contact\', \'image\'),
    \'add_new_item\' => __(\'Add New Contact\'),
    \'edit_item\' => __(\'Edit Contact\'),
    \'new_item\' => __(\'Add Contact\'),
    \'all_items\' => __(\'View Contacts\'),
    \'view_item\' => __(\'View Contact\'),
    \'search_items\' => __(\'Search Contacts\'),
    \'not_found\' =>  __(\'No Contacts found\'),
    \'not_found_in_trash\' => __(\'No Contacts found in Trash\'), 
    \'parent_item_colon\' => \'\',
    \'menu_name\' => \'Contacts\'
    );

    $tpf_cnm_type_args = array(
        \'labels\' => $tpf_cnm_type_labels,
        \'public\' => true,
        \'publicly_queryable\' => true,
        \'show_ui\' => true, 
        \'show_in_menu\' => true, 
        \'query_var\' => true,
        \'rewrite\' => array( \'slug\' => _x( \'contact-manager\', \'URL slug\', \'your_text_domain\' ) ),
        \'capability_type\' => \'post\',
        \'has_archive\' => true, 
        \'hierarchical\' => false,
        \'menu_position\' => null,
        \'supports\' => array( \'title\', \'comments\', \'custom-fields\' )
      ); 

    register_post_type(\'tpf_cnm\', $tpf_cnm_type_args); 
    }
任何帮助都会很好我快疯了提前谢谢大家

1 个回复
最合适的回答,由SO网友:Stephen S. 整理而成

我认为您可能需要更正:

\'post-type\' => \'tpf_cnm\',

并使其:

\'post_type\' => \'tpf_cnm\',

结束

相关推荐

Front-End Post Submission

我正在尝试添加一个表单,用户可以从前端提交帖子。我正在学习本教程:http://wpshout。com/wordpress从前端提交帖子/我正在做的是添加this code 到我的一个页面模板。表单显示正常,但当我单击“提交”按钮时,它会显示“Page not found error“”许多评论者说这不起作用。谁能给我指出正确的方向吗?代码是否不完整?有缺陷吗?我做错什么了吗?谢谢Towfiq I。