admin管理员组文章数量:1310081
I have this form that allows-me to change some things of the current post in my frontend:
<form id="featured_upload" name="featured_upload" method="post" action="#" enctype="multipart/form-data">
<p><span class="badge badge-primary"><input type="file" name="my_image_upload" id="my_image_upload" multiple="false" required /></span></p>
<p><input type="text" name="newtags" id="newtags" value="" placeholder="new tags aqui..." /> <input type="text" name="h2" id="h2" value="" placeholder="h2 heading aqui..." /></p>
<p><input type="hidden" name="post_id" id="post_id" value="" /></p>
<?php wp_nonce_field( 'my_image_upload', 'my_image_upload_nonce' ); ?>
<span class="badge badge-light" ><input id="" name="" type="submit" value="Upload"/></span>
</form>
Starting the saving process...
// Check the nonce is valid, and the user can edit this post.
if ( isset( $_POST['my_image_upload_nonce'], $_POST['post_id'] )
&& wp_verify_nonce( $_POST['my_image_upload_nonce'], 'my_image_upload' )
&& current_user_can( 'manage_options', $_POST['post_id'] )) {
What I would like to do is to have the habitability of changing the post title (and slug also, of course...).
Can this be implemented on this form?
I have this form that allows-me to change some things of the current post in my frontend:
<form id="featured_upload" name="featured_upload" method="post" action="#" enctype="multipart/form-data">
<p><span class="badge badge-primary"><input type="file" name="my_image_upload" id="my_image_upload" multiple="false" required /></span></p>
<p><input type="text" name="newtags" id="newtags" value="" placeholder="new tags aqui..." /> <input type="text" name="h2" id="h2" value="" placeholder="h2 heading aqui..." /></p>
<p><input type="hidden" name="post_id" id="post_id" value="" /></p>
<?php wp_nonce_field( 'my_image_upload', 'my_image_upload_nonce' ); ?>
<span class="badge badge-light" ><input id="" name="" type="submit" value="Upload"/></span>
</form>
Starting the saving process...
// Check the nonce is valid, and the user can edit this post.
if ( isset( $_POST['my_image_upload_nonce'], $_POST['post_id'] )
&& wp_verify_nonce( $_POST['my_image_upload_nonce'], 'my_image_upload' )
&& current_user_can( 'manage_options', $_POST['post_id'] )) {
What I would like to do is to have the habitability of changing the post title (and slug also, of course...).
Can this be implemented on this form?
Share Improve this question edited Nov 28, 2019 at 12:14 Chetan Vaghela 2,3984 gold badges10 silver badges16 bronze badges asked Nov 28, 2019 at 11:29 bpybpy 2995 silver badges20 bronze badges1 Answer
Reset to default 1Yes, you can change post title and slug from frontend. by using wp_update_post
you can change title and slug of post. in below code, it will update post title and slug of post_id
. Replace your-post-title-field
with your title field in form. slug will generated using that post title.
if ( isset( $_POST['my_image_upload_nonce'], $_POST['post_id'] )
&& wp_verify_nonce( $_POST['my_image_upload_nonce'], 'my_image_upload' )
&& current_user_can( 'manage_options', $_POST['post_id'] )) {
if(!empty($_POST['your-post-title-field']))
{
$new_slug = $new_title = sanitize_title($_POST['your-post-title-field']);
wp_update_post(
array (
'ID' => $_POST['post_id'],
'post_title' => $new_title,
'post_name' => $new_slug
)
);
}
}
本文标签: slugEdit the post title from the frontend
版权声明:本文标题:slug - Edit the post title from the frontend 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741854392a2401254.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论