0

I have published page with post type abc, but the page is not found. If I keep post type, then it works fine. I insert post data and publish through query:

add_action( 'init', 'my_cpt_init' );
function my_cpt_init() {
     register_post_type( 'abc',
        array(
            'labels' => array(
                'name' => __( 'abc' ),
                'singular_name' => __( 'abc' )
                ),
        'public' => true,
        'has_archive' => true,
        'rewrite' => array( 'slug' => 'abc' )
        )
    );
    flush_rewrite_rules();
}

function add_abc(){

   $my_post = array(
                      'post_title'    => wp_strip_all_tags( $project_name ),
                      'post_content'  => $project_name,
                      'post_status'   => 'publish',
                      'post_type'     => 'abc',
                    );

                    wp_insert_post( $my_post );
}
  • 1
    Is abc a valid post type that you have registered? – Milo Aug 22 '18 at 3:31
  • I am just inserting doing this $new_post = array( 'post_title' => $project_name, 'post_content' => $project_name, 'post_status' => 'publish', 'post_type' => 'abc', 'post_date' => date( 'Y-m-d H:i:s' ) ); $post_id = wp_insert_post( $new_post ); – Anusha Aug 22 '18 at 3:34
  • You have to register a post type with register_post_type. – Milo Aug 22 '18 at 3:36
  • Thank you my is custom plugin and my form form is different from Add new – Anusha Aug 22 '18 at 3:37
  • I am just inserting doing this $new_post = array( 'post_title' => $project_name, 'post_content' => $project_name, 'post_status' => 'publish', 'post_type' => 'abc', 'post_date' => date( 'Y-m-d H:i:s' ) ); $post_id = wp_insert_post( $new_post ); – Anusha Aug 22 '18 at 3:38

Your Answer

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

Browse other questions tagged or ask your own question.