homepage Welcome to WebmasterWorld Guest from 54.145.183.126
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / WordPress
Forum Library, Charter, Moderators: lorax & rogerd

WordPress Forum

    
User 'front end' posts code
user posts
roclimb

5+ Year Member



 
Msg#: 4563599 posted 7:30 pm on Apr 10, 2013 (gmt 0)

Hi all,

I have a tutorial I followed to let users submit posts through the front end and it works like a charm. My only problem is that all of my sites posts are output in a table at the bottom of my page.

I would like to modify the code so that only what a user types into the input fields is the only output onto that specific page and no other posts are populated on that page. Basically whatever they enter is posted on that page and nothing else.


Any way to do this?

My code:

<?php /* Template Name: Insert Posts */

$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;
} else {
$postTitle = trim($_POST['postTitle']);
}

$post_information = array(
'post_title' => esc_attr(strip_tags($_POST['postTitle'])),
'post_content' => esc_attr(strip_tags($_POST['postContent'])),
'post-type' => 'post',
'post_status' => 'pending'
);

$post_id = wp_insert_post($post_information);

if($post_id)
{

// Update Custom Meta
update_post_meta($post_id, 'vsip_custom_one', esc_attr(strip_tags($_POST['customMetaOne'])));
update_post_meta($post_id, 'vsip_custom_two', esc_attr(strip_tags($_POST['customMetaTwo'])));

// Redirect
wp_redirect( home_url() ); exit;
}

} ?>

<?php include ('header_state.php'); ?>


<!-- #primary BEGIN -->
<div id="primary">

<form action="" id="primaryPostForm" method="POST">

<fieldset>

<label for="postTitle"><?php _e('Post\'s Title:', 'framework') ?></label>

<input type="text" name="postTitle" id="postTitle" value="<?php if(isset($_POST['postTitle'])) echo $_POST['postTitle'];?>" class="required" />

</fieldset>

<?php if($postTitleError != '') { ?>
<span class="error"><?php echo $postTitleError; ?></span>
<div class="clearfix"></div>
<?php } ?>

<fieldset>

<label for="postContent"><?php _e('Post\'s Content:', 'framework') ?></label>

<textarea name="postContent" id="postContent" rows="8" cols="30"><?php if(isset($_POST['postContent'])) { if(function_exists('stripslashes')) { echo stripslashes($_POST['postContent']); } else { echo $_POST['postContent']; } } ?></textarea>

</fieldset>

<fieldset>

<label for="customMetaOne"><?php _e('Custom Meta One:', 'framework') ?></label>

<input type="text" name="customMetaOne" id="customMetaOne" value="<?php if(isset($_POST['customMetaOne'])) echo $_POST['customMetaOne'];?>" />

</fieldset>

<fieldset>

<label for="customMetaTwo"><?php _e('Custom Meta Two:', 'framework') ?></label>

<input type="text" name="customMetaTwo" id="customMetaTwo" value="<?php if(isset($_POST['customMetaTwo'])) echo $_POST['customMetaTwo'];?>" />

</fieldset>

<fieldset>

<?php wp_nonce_field('post_nonce', 'post_nonce_field'); ?>

<input type="hidden" name="submitted" id="submitted" value="true" />
<button type="submit"><?php _e('Add Post', 'framework') ?></button>

</fieldset>

</form>

</div><!-- #primary END -->





<div id="the-info">

<!-- #primary BEGIN -->
<div id="primary">

<?php if(isset($_GET['result'])) : ?>

<?php if($_GET['result'] == 'success') : ?>

<!-- .client_success BEGIN -->
<div class="client_success">

<span class="success">Successfully Added<span class="cross"><a href="#">X</a></span></span>

</div><!-- .client_success END -->

<?php endif; ?>

<?php endif; ?>

<table>

<tr>
<th>Post Title</th>
<th>Post Excerpt</th>
<th>Post Status</th>
<th>Actions</th>
</tr>




<?php $query = new WP_Query(array('post_type' => 'post', 'posts_per_page' =>'-1', 'post_status' => array('publish', 'pending', 'draft', 'private', 'trash') ) ); ?>

<?php if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post(); ?>

<tr>
<td><?php echo get_the_title(); ?></td>
<td><?php the_excerpt(); ?></td>
<td><?php echo get_post_status( get_the_ID() ) ?></td>

<?php $edit_post = add_query_arg('post', get_the_ID(), get_permalink(61 + $_POST['_wp_http_referer'])); ?>

<td>
<a href="<?php echo $edit_post; ?>">Edit</a>

<?php if( !(get_post_status() == 'trash') ) : ?>

<a onclick="return confirm('Are you sure you wish to delete post: <?php echo get_the_title() ?>?')"href="<?php echo get_delete_post_link( get_the_ID() ); ?>">Delete</a>

<?php endif; ?>
</td>
</tr>

<?php endwhile; endif; ?>

</table>

</div><!-- #primary END -->



</div>


<?php get_footer(); ?>

 

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / WordPress
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved