[英]Redirect on successful file upload when creating a new WordPress post using jQuery Form Plugin
I am trying to use malsup's jQuery Form Plugin to add a percentage progress bar to file uploads. 我正在尝试使用malsup的jQuery表单插件为文件上传添加百分比进度栏。 My form also captures post title and content and if everything is completed and submitted successfully a new WordPress post is created. 我的表单还捕获帖子的标题和内容,如果一切都已完成并成功提交,则将创建一个新的WordPress帖子。
My form: 我的表格:
<input type="text" name="post_title" />
<textarea name="post_text" rows="3"></textarea>
<input type="file" name="post_upload" id="file" />
<input id="submit" name='post_form_subimitted' type="submit" value="Submit" />
Aside from the form, I have these HTML elements on the page 除了表单之外,页面上还有这些HTML元素
<div class="progress">
<div class="bar"></div >
<div class="percent">0%</div >
</div>
<div id="status"></div>
My script: 我的剧本:
<script>
(function() {
var bar = $('.bar');
var percent = $('.percent');
var status = $('#status');
$('form').ajaxForm({
beforeSend: function() {
status.empty();
var percentVal = '0%';
bar.width(percentVal)
percent.html(percentVal);
},
uploadProgress: function(event, position, total, percentComplete) {
var percentVal = percentComplete + '%';
bar.width(percentVal)
percent.html(percentVal);
},
success: function() {
var percentVal = '100%';
bar.width(percentVal)
percent.html(percentVal);
},
complete: function() {
// -- i think this is the part I am struggling with -- //
}
});
})();
</script>
My question is, how can I redirect the user to the post on successful upload? 我的问题是,如何在成功上传后将用户重定向到帖子? The URL would be example.com/post_id
where post_id is auto generated on new post creation and will be something like 674
. 该URL为example.com/post_id
,其中post_id是在创建新帖子时自动生成的,类似于674
。
<?php
$last = wp_get_recent_posts( '1');
$last_id = $last['0']['ID'];
?>
this will return last post id so put a js code below the form submit code.. than $last_id will be holding the value u want. 这将返回最后一个帖子ID,因此将js代码放在表单提交代码下方。.而不是$ last_id将保存您想要的值。 hope this helps 希望这可以帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.