Programmmatically adding a Custom Post

I’ve added a custom post type, on the ‘init’ action, like so:

// Setup the 'Classifieds' Post Type
    $labels = array(
        'name' =>                   _x('Classifieds', 'post type general name'),
        'singular_name' =>          _x('Classifieds', 'post type singular name'),
        'add_new' =>                _x('Add New', 'classifieds'),
        'add_new_item' =>           __('Add Classifieds Item'),
        'edit_item' =>              __('Edit Classifieds'),
        'new_item' =>               __('New Classifieds Item'),
        'view_item' =>              __('View Classifieds'),
        'search_items' =>           __('Search Classifieds'),
        'not_found' =>              __('No classifieds found'),
        'not_found_in_trash' =>     __('No classifieds found in Trash'), 
        'parent_item_colon' =>      '',
        'menu_name' =>              'Classifieds'
    );

    // Configure the 'Classifieds' post type
    $args = array(
        'labels' =>                 $labels,
        'public' =>                 true,
        'publicly_queryable' =>     true,
        'show_ui' =>                true,
        'show_in_menu' =>           true, 
        'query_var' =>              true,
        'rewrite' =>                array("slug" => "classifieds"),
        'capability_type' =>        'post',
        'has_archive' =>            true, 
        'hierarchical' =>           true,
        'menu_position' =>          5,                                              
        'supports' =>               array('title',
                                        'editor',
                                        'author',
                                        'thumbnail',
                                        'excerpt',
                                        'trackbacks',
                                        'custom-fields',
                                        'revisions',
                                        'comments',
                                        add_theme_support( 'post-formats', 
                                                            array('aside', 'gallery')
                                                        )
                                    ),
        'taxonomies' => array('category', 'post_tag')
    );
    // Add the 'Classifieds' post type
    register_post_type('classifieds', $args);

My problem is when I want to insert a custom post programatically, like so:

Read More
$cat_ID = get_cat_ID( 'calendar' );

            $data = array(
                'post_content' => stripslashes($output),
                'post_title' => stripslashes($title),
                'post_date' => date('Y-m-d H:i:s'),
                'post_category' => array($cat_ID),
                'post_status' => $statusPost,
                'post_author' => $post_author
            );
            $post_id = wp_insert_post($data);

The custom post is displayed under the Admin’s generic ‘Post’ type post, not under the custom post type of ‘Classifieds’ which I created above.

Does anyone have any suggestions?

Related posts

Leave a Reply

1 comment

  1. you need to specify the post_type in your $data array :

    $data = array(
        'post_type' => 'classifieds',
        'post_content' => stripslashes($output),
        'post_title' => stripslashes($title),
        'post_date' => date('Y-m-d H:i:s'),
        'post_category' => array($cat_ID),
        'post_status' => $statusPost,
        'post_author' => $post_author
    );