How do I programmatically add items of content to a custom post type?

You should first run the wp_insert_post() which will return the post ID. Then use that post ID to add your custom fields. Use add_post_meta() to add the custom fields.

$post_id = wp_insert_post( $args );

add_post_meta( $post_id, 'longitude', $my_long );
add_post_meta( $post_id, 'latitude', $my_lat );

For image attachments, you can refer to this question: How to set featured image to custom post from outside programmatically

Leave a Comment