I'm trying to create custom posts in the code of my template in Wordpress.
<div class="demo">
<?php global $user_ID;
$new_post = array(
'post_title' => 'My New Post',
'post_content' => 'Lorem ipsum dolor sit amet...',
'post_status' => 'publish',
'post_date' => date('Y-m-d H:i:s'),
'post_author' => $user_ID,
'post_type' => 'post',
'post_category' => array(0)
);
$post_id = wp_insert_post($new_post); ?>
</div>
This doesn't seem to display the post on the page?
<div class="demo">
<?php global $user_ID;
$new_post = array(
'post_title' => 'My New Post',
'post_content' => 'Lorem ipsum dolor sit amet...',
'post_status' => 'publish',
'post_date' => date('Y-m-d H:i:s'),
'post_author' => $user_ID,
'post_type' => 'post',
'post_category' => array(0)
);
$post_id = wp_insert_post($new_post); ?>
What above code does is insert a new post. Read more
This doesn't seem to display the post on the page?
What you are trying to do here is inserting a new post. if you want that post to be shown try the below code
<?php get_post( $post_id ); ?>
Read more