I created a new PHP template inside my root directory alongside index.php
named 'template-insert-posts.php
. However, when I try to access the following URL: http://localhost/wordpress/template-insert-posts.php
, I get the following error:
Object not found! The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.
I am able to access the index.php
template by entering the URL http://localhost/wordpress/index.php
Now, both index.php
and template-insert-posts.php
are located in the same path ie /opt/lampp/htdocs/wordpress/wp-content/themes/twentyfifteen
. Then, why is my template-insert-posts.php
not accessible? Is there something I'm missing before trying to access a custom template in Wordpress? Also, here's the source code of the file:
template-insert-posts.php
<?php
$postTitleError = '';
if ( isset( $_POST['submitted'] ) && isset( $_POST['post_nonce_field'] ) && wp_verify_nonce( $_POST['post_nonce_field'], 'post_nonce' ) ) {
if ( trim( $_POST['postTitle'] ) === '' ) {
$postTitleError = 'Please enter a title.';
$hasError = true;
}
$post_information = array(
'post_title' => wp_strip_all_tags( $_POST['postTitle'] ),
'post_content' => $_POST['postContent'],
'post_type' => 'post',
'post_status' => 'pending'
);
wp_insert_post( $post_information );
}
$post_id = wp_insert_post( $post_information );
if ( $post_id ) {
wp_redirect( home_url() );
exit;
}
?>
<?php
get_header(); ?>
<form action="" id="primaryPostForm" method="POST">
<fieldset>
<label for="postTitle"><?php _e('Post Title:', 'framework') ?></label>
<input type="text" name="postTitle" id="postTitle" class="required" value="<?php if ( isset( $_POST['postTitle'] ) ) echo $_POST['postTitle']; ?>"/>
</fieldset>
<fieldset>
<label for="postContent"><?php _e('Post Content:', 'framework') ?></label>
<textarea name="postContent" id="postContent" rows="8" cols="30" class="required" <?php if ( isset( $_POST['postContent'] ) ) { if ( function_exists( 'stripslashes' ) ) { echo stripslashes( $_POST['postContent'] ); } else { echo $_POST['postContent']; } } ?>></textarea>
</fieldset>
<fieldset>
<input type="hidden" name="submitted" id="submitted" value="true" />
<?php wp_nonce_field( 'post_nonce', 'post_nonce_field' ); ?>
<button type="submit"><?php _e('Add Post', 'framework') ?></button>
</fieldset>
</form>
<?php get_footer(); ?>