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.

5 s
5

From the Codex:

wp_insert_post() will fill out a default list of these but the
user is required to provide the title and content otherwise the
database write will fail.

$id = wp_insert_post(array(
  'post_title'=>'random', 
  'post_type'=>'custom_post', 
  'post_content'=>'demo text'
));

Leave a Reply

Your email address will not be published. Required fields are marked *