Can’t use wp_insert_post function with custom post type
-
created a custom post type with CPT plugin. It’s works fine and did the job. I can create post, publish the post and i can see on the site. But when i create a post from frontend via wp_insert_post it’s creates the post but i can’t see on site. It gives me 404.
$post_args = array( 'post_type' => 'm', 'post_title' => $menuName . ' | ' . $postId, 'post_name' => "".$postId."", 'post_content' => '', 'post_status' => 'publish', 'post_author' => get_current_user_id(), ); $post_id = wp_insert_post($post_args); if(!is_wp_error($post_id)){ echo 'created ' . $post_id; } else { //there was an error in the post insertion, echo $post_id->get_error_message(); }When i create a post:
img 1 linkWhen i publish and see on site:
img 2 linkNote: wp_insert_post works just fine when change post_type to post
- This topic was modified 3 years, 9 months ago by .
- This topic was modified 3 years, 9 months ago by .
- This topic was modified 3 years, 9 months ago by .
- This topic was modified 3 years, 9 months ago by .
- This topic was modified 3 years, 9 months ago by .
- This topic was modified 3 years, 9 months ago by .
- This topic was modified 3 years, 9 months ago by .
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
The topic ‘Can’t use wp_insert_post function with custom post type’ is closed to new replies.