I created a front end form and want to create the page title via a field. When i submit the form, in the dashboard the Page Name shows in the Post Title, however the permalink of the page shows the post id.
example.
http://www.mywebsite.com/cpt/174
when it should show
http://www.mywebsite.com/cpt/my-page-title
—-
My functions.php
add_filter(‘acf/pre_save_post’, ‘save_post_from_frontend’);
function save_post_from_frontend( $post_id) {
//Check if user loggin or can publish post
if( ! ( is_user_logged_in() || current_user_can(‘publish_posts’) ) ) {
return;
}
// check if this is to be a new post
if( $post_id!= ‘firm-profile’) {
return $post_id;
}
$post= array(
‘post_type’ => ‘providers’, // Your post type ( post, page, custom post type )
‘post_status’ => ‘publish’, // (publish, draft, private, etc.)
‘post_title’ => $_POST[‘fields’][‘field_5e0b90db10390’]
);
// insert the post
$post_id= wp_insert_post( $post);
$_POST[‘return’] = add_query_arg( array(‘post_id’ => $post_id), $_POST[‘return’] );
// Save the fields to the post
do_action( ‘acf/save_post’, $post_id);
return $post_id;
}
My Custom Template:
<div class=” form-group”>
<label for=”text” class=” control-label”><?php esc_html_e(‘Firm Profile’,’falcons’); ?></label>
<div class=” “>
<?php
$new_post= array(
‘post_id’ => ‘firm-profile’, // Unique identifier for the form
// PUT IN YOUR OWN FIELD GROUP ID(s)
‘field_groups’ => array(594), // Create post field group ID(s)
‘form’ => true,
‘submit_value’ => ‘Submit Post’,
‘updated_messag’ => ‘Saved!’
);
acf_form( $new_post);
?>
<?php acf_form(); ?>
</div>
</div>
—- Versions —-
ACF v5.8.7
WP v5.3.2