@andystillalive,
Please follow below steps in order to create dynamic page using custom PHP Based wordpress code:
1) You’ve to create custom template file in your current theme. (i.e. custompage.php) and which contains code below:
<?php
/*
Template Name: Custom Page Template
*/
get_header();
// Here is your custom form whatever you want to add field.
?><form action="" method="post">
Name : <input type="text" name="postTitle" value=""><br>
Title : <input type="text" name="postContent" value="">
<input type="submit" name="submit" value="submit">
</form><?php
get_footer();
?>
2) Your template file is ready. Now, We’ve to handle the form data & store into our database for future use. So, that you’ve to add below code into your current theme’s function.php file.
if(isset($_REQUEST['submit'])){
$post_information = array(
'post_title' => $_POST['postTitle'] ,
'post_content' => $_POST['postContent'],
'post_type' => 'page',
'post_status' => 'pending'
);
$post_id = wp_insert_post( $post_information );
if ( $post_id ) {
wp_redirect( home_url() );// Here give your thank you page url.
exit;
}
}
Note : All Changes you done in function.php or other file are gone when you update theme. So prefer Child Theme
Hope this will helps you.
Thanks!