I don’t understand why you registered a shortcode if you aren’t using it. Your custom-form.php
‘s code can be:
<?php
/**
* Template Name: My Custom Form
*/
get_header();
echo do_shortcode('[custom_posts]');
get_footer();
?>
Now, back to your question, how to save and/or get the custom field value. Well, your method of saving the custom field (meta) value is totally incorrect. I wonder what you got in SERPs when you searched for a related query, or did you even search?
To save post_meta
value, first get ID of the newly created post and the save the custom field value. To make the answer shorter, I’ll include the relevant code only
$post = array(
'post_title' => wp_strip_all_tags( $title ),
'post_content' => $description,
'post_category' => $_POST['cat'],
'tags_input' => $tags,
'post_status' => 'publish',
'post_type' => 'custom_posts'
);
$post_id = wp_insert_post($post);
add_post_meta( $post_id, 'custom_field_one', $custom_field_one, false );
You can also do this
$post = array(
'post_title' => wp_strip_all_tags( $title ),
'post_content' => $description,
'post_category' => $_POST['cat'],
'tags_input' => $tags,
'post_status' => 'publish',
'post_type' => 'custom_posts',
'meta_input' => array(
'custom_field_one' => $custom_field_one
)
);
$post_id = wp_insert_post($post);
Disclaimer: I am not sure about the rest of the code but only assisted with what was asked.