post_status => publish not working

I have a front end form that let users submit a post.

This is how i store the data when a post is submitted :

if ( isset( $_POST['submitted'] )) {
        $post_information = array(
        'post_title' => wp_strip_all_tags( $_POST['postTitle'] ),
        'post_content' => $_POST['postContent'],
        'post_type' => 'post',
        'post_status' => 'publish'
    );
$new_post = wp_insert_post( $post_information );

The post is not showing in my post page unless i go through my dashboard and click over The UPDATE button.

THIS IS HOW I QUERY MY POSTS :

$args = array(
 'posts_per_page' => 5,
'paged' => $paged,
'meta_query' => array(
array( 'key' => '_wti_like_count','value' => 5, 'compare' => '<=','type' => 'numeric')
)
);

query_posts( $args );

How can i make my submitted posts publish automatically?

2 Answers
2

The post gets added and published but since you have the meta query and the meta key is not added when you submit the post from frontend, it does not show up. Use the following code which adds the meta data as needed.

if ( isset( $_POST['submitted'] ) ) {
     $post_information = array(
                              'post_title' => wp_strip_all_tags( $_POST['postTitle'] ),
                              'post_content' => $_POST['postContent'],
                              'post_type' => 'post',
                              'post_status' => 'publish'
                         );

     $new_post = wp_insert_post( $post_information );

     // Add the post meta
     add_post_meta( $new_post, '_wti_like_count', 0, true );
     add_post_meta( $new_post, '_wti_unlike_count', 0, true );
     add_post_meta( $new_post, '_wti_total_count', 0, true );
}

Leave a Comment