我希望能够允许用户register/login via a front end form 并且能够create 1 custom post 只有他们才能做到edit and update via a front end form.
这将是“仪表板”的一部分。
It\'s very important that this works with the http://www.advancedcustomfield.com plugin.
通过使用ACF的前端表单,我成功地实现了一些目标。这允许编辑和更新自定义帖子。
问题在于:
没有前端注册/登录帖子已经创建,而我需要一个用户登录并最初创建一篇帖子我只能在实际页面上对文章进行前端编辑。我需要用户只能编辑自己的帖子
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:
我发现这将允许我通过前端表单创建新帖子。使用
action
我想我可以将用户重定向到他们刚刚创建的自定义帖子。因此,这将允许他们通过下面的第二个代码框更新/编辑帖子。
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>
下面的代码允许用户编辑/更新他们刚刚创建的帖子。
<?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(); ?>