0

This is my custom post type code everything working fine but when i publish post, the post is being saved in draft mode.

     $args = array(
        'labels' => $labels,
        'public' => true,
        'publicly_queryable' => true,
        'show_ui' => true,
        'show_in_menu' => true,
        'query_var' => true,
        'rewrite' => array('slug' => $slug),
        'capability_type' => 'post',
        'has_archive' => true,
        'hierarchical' => false,
        'menu_position' => 4,
        'supports' => $supports,
        'taxonomies' => array( 'category' ),
    );

    register_post_type(self::$PostTypeName, $args);
0

Use 'wp_insert_post_data' filter hook for that kind of problem

add_filter('wp_insert_post_data', 'filter_post_data', 99, 2);

function filter_post_data($postData, $postarr) {

    if ($postData['post_status'] == 'draft') {
        $postData['post_status'] = 'publish';
    }

    return $postData;
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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