Need to insert custom post type objects from code. Haven’t been able to add using the default method
$id = wp_insert_post(array('post_title'=>'random', 'post_type'=>'custom_post'));
creates a regular post instead.
Need to insert custom post type objects from code. Haven’t been able to add using the default method
$id = wp_insert_post(array('post_title'=>'random', 'post_type'=>'custom_post'));
creates a regular post instead.
Comments are closed.
From the Codex:
It can be done using the following code :-
To enter a new post for a custom type
After inserting the post, a post id will be returned by the above function. Now if you want to enter any post meta information w.r.t this post then following code snippet can be used.
This example worked for me using meta_input
I found using
isset()
allowed me to usewp_insert_post()
on custom post types:I had the same problem. I tried every solution provided in most of the forums. But the actual solution that worked for me was the post type was the length of post_type.
The post_type length is limited to 20 characters. So anyone who has a similar issue try this if anything else didn’t work.