WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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',
                                        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:

$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?

share|improve this question
up vote 5 down vote accepted

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
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.