I want to be able to allow a user to register/login via a front end form and be able to create 1 custom post which only they will be able to edit and update via a front end form.
This will be part of a "dashboard".
It's very important that this works with the http://www.advancedcustomfield.com plugin.
I've managed to get some of the way there by using the front end forms from ACF. This allows the editing and updating of a custom post.
The problem with this is that:
- There is no front end registration/login.
- The post was already created, whereas I need a user to login and create 1 post initially.
- I'm only able to front end edit the post when I'm on the actual page. I need the user to only be able to edit their own post.
If anyone could point me in the right direction with those issues or has any creative ways to get around them then that would be great. I need to do this without using lot's of other plugins.
UPDATE:
I've found that this will allow me to create a new post via a front end form. Using the action
of the form I think I can redirect the user to the custom post they just created. Therefore that will allow them to update/edit the post via the 2nd code box below.
So all that I need to do is the user registration/login!
<?php $postTitle = $_POST['post_title'];
$post = $_POST['post'];
$submit = $_POST['submit'];
if(isset($submit)){
global $user_ID;
$new_post = array(
'post_title' => $postTitle,
'post_content' => $post,
'post_status' => 'publish',
'post_date' => date('Y-m-d H:i:s'),
'post_author' => $user_ID,
'post_type' => 'post',
'post_category' => array(0)
);
wp_insert_post($new_post);
}
?>
<!DOCTYPE HTML SYSTEM>
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled Document</title>
</head>
<body>
<div id="wrap">
<form action="" method="post">
<table border="1" width="200">
<tr>
<td><label for="post_title">Post Title</label></td>
<td><input name="post_title" type="text" /></td>
</tr>
<tr>
<td><label for="post">Post</label></td>
<td><input name="post" type="text" /></td>
</tr>
</table>
<input name="submit" type="submit" value="submit" />
</form>
</div>
</body>
</html>
The code below allows the user to edit/update the post they just created.
<?php
/**
* @package WordPress
* @subpackage Default_Theme
* Template Name: Login
*/
acf_form_head();
get_header(); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div style="width:719px;">
<?php global $current_user;
get_currentuserinfo();
$page_name = $current_user->user_login; ?>
Logged in as: <?php echo $page_name; ?> (<?php echo $current_user->ID; ?>)
<br />
List posts by <?php echo $page_name; ?>:
<?php
$loop = new WP_Query( array(
'post_type' => 'page',
'author' => $current_user->ID
));
while ( $loop->have_posts() ) : $loop->the_post();
the_title();
echo "<br>";
endwhile;
//Reset Query
wp_reset_query();
?>
<?php $defaults = array(
'post_id' => $post->ID, // post id to get field groups from and save data to
'field_groups' => array(), // this will find the field groups for this post (post ID's of the acf post objects)
'form_attributes' => array( // attributes will be added to the form element
'class' => ''
),
'return' => add_query_arg( 'updated', 'true', get_permalink() ), // return url
'html_field_open' => '<div class="field">', // field wrapper open
'html_field_close' => '</div>', // field wrapper close
'html_before_fields' => '', // html inside form before fields
'html_after_fields' => '', // html inside form after fields
'submit_value' => 'Update', // value for submit field
'updated_message' => 'Post updated.', // default updated message. Can be false to show no message
);
acf_form(); ?>
</div>
<?php endwhile; ?>
<?php endif; ?>
<?php get_footer(); ?>